2016-12-15 4 views
0
NSDate *now = [NSDate date]; 
    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    // find next date where the minutes are zero 
    NSDate *nextHour = [calendar nextDateAfterDate:now matchingUnit:NSCalendarUnitMinute value:0 options:NSCalendarMatchNextTime]; 
    // get the number of seconds between now and next hour 
    NSDateComponents *componentsToNextHour = [calendar components:NSCalendarUnitSecond fromDate:now toDate:nextHour options:0]; 
    //NSLog(@"%ld", componentsToNextHour.second); 
    NSString *dec = [NSString stringWithFormat:@"%ld", (long)componentsToNextHour.second]; 

위의 코드에서 현재 날짜와 시간을 초로 변환하지만이 초를 unixtimestamp로 변환 할 수 없으므로이 방법에 대한 아이디어는 높이 평가 될 것입니다.객관적인 C에서 초를 UnixTimeStamp로 변환하는 방법?

답변

1

귀하의 질문에 대한 확신이 없습니다. 당신이 다음 시간이 시작되는 유닉스 타임 스탬프를 요구하는 경우, 다음을 수행

NSDate *now = [NSDate date]; 
    NSCalendar *calendar = [NSCalendar currentCalendar]; 
    // find next date where the minutes are zero 
    NSDate *nextHour = [calendar nextDateAfterDate:now matchingUnit:NSCalendarUnitMinute value:0 options:NSCalendarMatchNextTime]; 
    time_t unixTimestampAtWhichNextHourStarts = (time_t)nextHour.timeIntervalSince1970; 
    NSLog(@"ts=%ld", (long)unixTimestampAtWhichNextHourStarts); 
+0

이 우수한, 그래서 내가 먼저 초에 변환 환상적인, 매우 감사, 당신은 시간의 내을 절약 할 필요가없는, 내가했다 그것에 시간을 찔렀다. –