I'm trying to get an NSDate object that has 21:00 as the local time - don't care about what day. I'm scratching my head at this very strange result:
NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setHour:21];
[components setMinute:0];
[components setSecond:0];
NSDate *date = [calendar dateFromComponents:components];
NSLog(@"%@", date);
The result is 0001-01-02 04:52:58 +0000
I have no idea why. The current time is 17:34 PST, but the result doesn't change with the local time.
If I adjust the setMinute and setSecond lines to
[components setMinute:7];
[components setSecond:2];
I get 0001-01-02 05:00:00 +0000
, which is correct (21:00 PST).