Dateformatter会给出错误的会话时间 [英] Dateformatter gives wrong time on conversation
本文介绍了Dateformatter会给出错误的会话时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的日期字符串转换为 NSDate
,但它返回正确的日期和错误的时间。
I am trying to convert my date string to NSDate
but its return correct date and wrong time.
这是我的代码:
NSString *dateStr = @"2013-12-20 12:10:40";
// Convert string to date object
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
NSDate *lastUpdatedate = [dateFormatter dateFromString:dateStr];
NSLog(@"lastUpdatedate : %@",lastUpdatedate);
它返回:
lastUpdatedate : 2013-12-20 06:40:40 +0000
推荐答案
- [NSDate description]
(将其传递给 NSLog
时调用)始终以GMT时区打印日期对象,而不是您当地的时区。如果您想要准确的字符串表示日期,请使用日期格式化程序根据您的时区创建正确的字符串。
- [NSDate description]
(which is called when passing it to NSLog
) always prints the date object in GMT timezone, not your local timezone. If you want an accurate string representation of the date, use a date formatter to create a correct string according to your timezone.
这篇关于Dateformatter会给出错误的会话时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文