为什么我得到这个输出时间:
2013-01-12 18:24:37.783 代码测试[10328:c07] 0001-01-01 17:12:52 +0000
当我运行此代码时:
NSCalendar *calendar = [NSCalendar currentCalendar];
calendar.timeZone = [NSTimeZone localTimeZone];
NSDateComponents *components = [calendar components:NSHourCalendarUnit fromDate:[NSDate date]];
components.hour = 17;
components.minute = 47;
components.second = 0;
NSDate *fire = [calendar dateFromComponents:components];
NSLog(@"%@", fire);
我试过默认时区,系统时区。它总是给我不同的分钟和秒的输出!加上错误的日期 0001-01-01!!!! 知道为什么吗?
附加测试:
运行此代码时:
NSCalendar *calendar = [NSCalendar currentCalendar];
calendar.timeZone = [NSTimeZone localTimeZone];
NSDateComponents *components = [calendar components:NSHourCalendarUnit fromDate:[NSDate date]];
components.hour = (components.hour + 1) % 24;
components.minute = 0;
components.second = 0;
NSDate *fire = [calendar dateFromComponents:components];
NSLog(@"%@", fire);
它给了我这个输出:
2013-01-12 18:41:41.552 代码测试[10648:c07] 0001-01-01 18:25:52 +0000
2013-01-12 18:42:16.274 代码测试[10648:c07] 0001-01-01 18:25:52 +0000
2013-01-12 18:42:30.310 代码测试[10648:c07] 0001-01-01 18:25:52 +0000