Converting timestamp string with T and Z characters to NSDate [duplicate]

帅比萌擦擦* 提交于 2019-12-23 06:35:06

问题


I don't know how to convert this string to NSDate.

Date is in this format "2012-10-21T07:00:00Z"

I guess the problem is that I have no clue what those T and Z mean in the string :)

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"];
NSDate *dateStart = [formatter dateFromString:@"2012-10-21T07:00:00Z"];

// format that I want
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];

NSLog(@"date: %@", [formatter stringFromDate:dateStart]);

all dates are in that format: 2014-09-12T03:46:25Z


回答1:


That is an ISO date. The Z stands for Zulu but means UTC time.

Try:

[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];

To feed your initial nsdate.



来源:https://stackoverflow.com/questions/25815818/converting-timestamp-string-with-t-and-z-characters-to-nsdate

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