NSDateFormatter doesn't convert my NSString in NSDate

落花浮王杯 提交于 2019-12-01 21:13:41

I think that instead of the format string yyyy-MM-dd HH:mm:ss.ZZZ, you will want yyyy-MM-dd HH:mm:ss.SSS.

ZZZ will be a timezone value, whereas SSS is fractional seconds.

See the Unicode documentation (linked from Apple's docs on Data Formatting)

Edit: one other thing: you don't need to have the line NSDate *dateFromString = [[NSDate alloc] init];. Just call NSDate *dateFromString = [dateFormatter dateFromString:fecha];. The date formatter will allocate the date object as it needs to.

ZZZ is a time zone format, it's looking for something like CET not the fractional part of the seconds. You want SSS

@"yyyy-MM-dd HH:mm:ss.SSS"

http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!