NSDate的DateTime [英] DateTime to NSDate
问题描述
如何将字符串2010-11-19T20:00:00Z
转换为NSDate
对象?
How do I convert string 2010-11-19T20:00:00Z
into an NSDate
object?
我尝试使用[dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]
,但看起来自定义格式样式错误.
I've tried using [dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]
but it looks like I got the wrong custom format style.
PS:我不在乎时区.实际上,我希望日期保留在原始(UTC)时区.
PS: I don't care about Timezones. Actually, I want the date to stay in the original (UTC) timezone.
推荐答案
尝试使用格式字符串将Nemate中的从转换为字符串,并查看得到的结果.在该方向上进行调试比其他方向更容易.
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.
在这种情况下,看起来好像您需要在模式中转义T和Z文字.像这样:
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'"];
这篇关于NSDate的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!