DateTime to NSDate

独自空忆成欢 提交于 2019-12-09 13:23:26

问题


How do I convert string 2010-11-19T20:00:00Z into an NSDate object?

I've tried using [dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"] but it looks like I got the wrong custom format style.

PS: I don't care about Timezones. Actually, I want the date to stay in the original (UTC) timezone.


回答1:


Try using your format string to convert from an NSDate to a string and see what you get. It's easier debugging in that direction than the other.

In this case, looks as though you need to escape the T and Z literals in your pattern. Something like this:

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];


来源:https://stackoverflow.com/questions/4179993/datetime-to-nsdate

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