0

我是菜鸟...我有

QuitTime.text = quitDate;

哪个是过去的日期...如何显示天、小时、分钟和秒的差异,然后实时更新?

4

1 回答 1

0

您可以使用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]);

参考:两个 NSDate 对象之间的区别——结果也是一个 NSDate

于 2012-11-15T07:01:53.070 回答