小编Why*_*ely的帖子

为什么我输出错误的时间与正确的时区?

为什么我得到这个输出时间:

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);
Run Code Online (Sandbox Code Playgroud)

我尝试过默认时区,系统时区.它总是给我一个不同的分钟和秒的输出!加错了日期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); …
Run Code Online (Sandbox Code Playgroud)

xcode timezone objective-c ios output

4
推荐指数
1
解决办法
495
查看次数

标签 统计

ios ×1

objective-c ×1

output ×1

timezone ×1

xcode ×1