我一直在研究一个应用程序,我将秒表集成到一个应用程序中。我有秒表正常工作,并显示秒/分钟等。
NSDate增加了一天
但我的问题是,我要当任务已经完成,以显示完整的时间
但每当(您可以在1天,2小时,3分4秒等完成了这个任务)我做它,它总是增加1天的等式(例如它应该是0天,0小时,2分14秒),但它输出1天,0小时,2分14秒。
代码:
startDate = [[NSDate date] retain];
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"D' Days, 'H' Hours, 'm' Minutes and 's' Seconds'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString = [dateFormatter stringFromDate:timerDate];
overtext2.text = timeString;
[dateFormatter release];
为什么你需要计时器的时间间隔,然后将其添加到1/1/1970? – bdesham 2013-02-15 15:48:37