I have a call to NScalendar components:fromDate: that fills all the values specified in the listed components except for NSCalendarUnitHour. Can anyone help me find out why?
NSCalendar* _cal = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
[_cal setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents* resultComponents = [_cal components:NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitMonth fromDate:result];
//result is 2018-03-18 05:48:36 +0000
//resultComponents
//<NSDateComponents: 0x60400014f0a0>
//Month: 3
//Leap month: no
//Day: 18
//Hour: 0
//Minute: 48
Why would Hour be set to 0?
The questions from @rmaddy and @Ken Thomases alerted me to the fact that my question did not take into account my current -5 timezone. I thought my timezone was -6 and so I was expecting any value other than 0. (Happy daylight savings...)
My solution to not worry about changing timezones was to change to this:
[_cal setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];