NSDateFormatter dateFromString 结果对我来说没有意义
以下代码:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = @"yyyy-MM-dd";
NSDate *tempDate = [dF2 dateFromString:@"2011-07-10"];
DebugLog(@"Temp Date %@", tempDate);
产生以下输出:
Temp Date 2011-07-10 05:00:00 +0000
我不明白 05:00:00 来自哪里?我在中央时区(格林尼治标准时间-5)使用此代码,这是我能想到的与设置日期的时间的唯一联系。我预计是 00:00:00。
欢迎输入。
The following code:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter.dateFormat = @"yyyy-MM-dd";
NSDate *tempDate = [dF2 dateFromString:@"2011-07-10"];
DebugLog(@"Temp Date %@", tempDate);
Results in the following output:
Temp Date 2011-07-10 05:00:00 +0000
I don't understand where the 05:00:00 is coming from? I am using this code in the Central timezone, which is -5 GMT and that's the only connection I can think of to the time that set for the date. I expected 00:00:00.
Input appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您创建 NSDate 07-10-2011 时,NSDataFormatter 默认为当前时区。在您的示例中是 GMT-5。
还要记住,调试器将以 UTC/GMT+0 显示 NSDate;
如果您想创建 UTC 午夜:
When you created the NSDate 07-10-2011 the NSDataFormatter defaults to current timezone. Which in your example is GMT-5.
Remember also, the debugger will display NSDate in UTC/GMT+0;
If you want to create UTC midnight: