我是菜鸟...我有
QuitTime.text = quitDate;
哪个是过去的日期...如何显示天、小时、分钟和秒的差异,然后实时更新?
您可以使用NSDateComponents
NSDate *currentDate = [NSDate date];
NSCalendar *gregorian = [[[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:quitDate
toDate:currentDate options:0];
NSLog(@"Component Month:%d",[component month]);
NSLog(@"Component Day:%d",[component day]);
NSLog(@"Component Hour:%d",[component hour]);
NSLog(@"Component Mins:%d",[component minute]);