[英]DateTime to NSDate
How do I convert string 2010-11-19T20:00:00Z
into an NSDate
object? 如何将字符串2010-11-19T20:00:00Z
转换为NSDate
对象?
I've tried using [dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]
but it looks like I got the wrong custom format style. 我尝试过使用[dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]
但看起来我的自定义格式样式不对。
PS: I don't care about Timezones. PS:我不关心时区。 Actually, I want the date to stay in the original (UTC) timezone. 实际上,我希望日期保留在原始(UTC)时区。
Try using your format string to convert from an NSDate to a string and see what you get. 尝试使用您的格式字符串从 NSDate 转换为字符串,看看你得到了什么。 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. 在这种情况下,看起来好像你需要在模式中转义T和Z文字。 Something like this: 像这样的东西:
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.