0

我只是在玩计时器,我发现了这个:

 - (void)viewDidLoad{
     [super viewDidLoad];
     NSDate *date = [NSDate date];
     dFormatter = [[NSDateFormatter alloc] init]; //instance variable

     NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

     unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
     NSDateComponents *dateC = [calendar components:unitFlags fromDate:date];
     [dateC setSecond:1];
     [dateC setHour:0];
     [dateC setMinute:0];

     NSDate *fireDate = [calendar dateFromComponents:dateC];
     [dFormatter setTimeStyle:NSDateFormatterLongStyle];
     [dFormatter setDateStyle:NSDateFormatterMediumStyle];
     NSLog(@"%@", [dFormatter stringFromDate:fireDate]);
 }

输出惊人:Oct, 4 12:00:01 AM

我正在尝试设置一个从过去几个小时开始的计时器触发日期。

我应该报告这个,还是有办法让那个日期变成像 oct, 4 00:00:01 AM?

4

1 回答 1

1

12:00:01 AM 等于午夜后 1 秒。或者我在这里错过了什么?

于 2013-10-04T15:02:20.637 回答