[英]NSDateFormatter dateFromString returning wrong date
Quick question. 快速提问。
I have a string date: example var dateString = "17-02-2015"
我有一个字符串日期:example
var dateString = "17-02-2015"
I use: 我用:
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
var newDate = dateFormatter.dateFromString(dateString)
And I get the output: 2015-01-16 23:02:00 +0000
然后我得到输出:
2015-01-16 23:02:00 +0000
Why am I missing a day? 为什么我想念一天? Is it because of the time zone?
是因为时区吗? (I am at +1, and in the date the timezone is 0?).
(我是+1,而时区是0?)。
I also tryed setting the time zone: 我还尝试设置时区:
dateFormatter.locale = NSLocale.currentLocale()
dateFormatter.timeZone = NSTimeZone.systemTimeZone()
But no success. 但是没有成功。
What am I missing? 我想念什么?
Thats the UTC time and it is correct considering the fact that your LocalTime is 1+ 那就是UTC时间,考虑到您的LocalTime是1+
var dateString = "17-02-2015"
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
var newDate = dateFormatter.dateFromString(dateString)!
println(newDate.descriptionWithLocale(NSLocale.currentLocale())!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.