我只是在玩计时器,我发现了这个:
- (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?