12:00:01 AM is equal to 1 second after midnight. Or am I missing something here?
Possible bug in NSDateCompononents?
-
30-06-2022 - |
Question
I was simply playing around with timers and i found this:
- (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]);
}
The output is amazingly : Oct, 4 12:00:01 AM
I'm trying to set up a timer-fire-date that starts some hours in the past.
Should i report this, or is there a way to make that date become something like oct, 4 00:00:01 AM???
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow