NSCalendar components:fromDate: 未填充 NSCalendarUnitHour

NSCalendar components:fromDate: not filling NSCalendarUnitHour

我调用了 NScalendar components:fromDate:它填充了列出的组件中指定的所有值,NSCalendarUnitHour 除外。谁能帮我看看为什么?

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

为什么 Hour 会设置为 0?

@rmaddy 和@Ken Thomases 的问题提醒我,我的问题没有考虑到我当前的 -5 时区。我以为我的时区是 -6,所以我期待 0 以外的任何值。(夏令时快乐...)

我不用担心更改时区的解决方案是更改为:

[_cal setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];