NSDate *today = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[calendar setLocale:[NSLocale currentLocale]];
[calendar setTimeZone:[NSTimeZone timeZoneWithName:@"US/Central"]];
NSDateComponents *nowComponents = [calendar components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];
[nowComponents setHour:hour];
[nowComponents setMinute:0];
[nowComponents setSecond:0];
NSLog(@"%@", [calendar dateFromComponents:nowComponents]);
日志2012-01-01 06:00:00 +0000
。根据时区设置,时间是正确的,但今天是 7 月 20 日……我做错了什么?