问题
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