我正在尝试建立一个倒计时,它显示要走的秒数。
下面的示例设置为 10 秒,但输出为 8 秒。
NSDate *currentDate = [NSDate date];
NSDate *finishDate = [NSDate dateWithTimeInterval:10 sinceDate:currentDate];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [calendar components:NSSecondCalendarUnit|NSMinuteCalendarUnit|NSHourCalendarUnit | NSDayCalendarUnit| NSMonthCalendarUnit | NSYearCalendarUnit
fromDate:currentDate
toDate:finishDate
options:0];
NSInteger hour_ = [components hour];
NSInteger minute_ = [components minute];
NSInteger second_ = [components second];
日志
currentDate = 2012-06-05 03:13:10 +0000
finishDate_ = 2012-06-05 03:13:19 +0000
second_ = 8