-2

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

budiDino
  • 13,044
  • 8
  • 95
  • 91

1 Answers1

2

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.

Martin
  • 1,135
  • 1
  • 8
  • 19
  • 1
    Actually, based on that single sample it's not clear whether the format should end with ZZZZZ or just Z. One would need to know how the timezone is expressed when it's not UTC. – Hot Licks Sep 12 '14 at 20:07
  • 1
    (The thing that fixed it was putting `T` in single quotes.) – Hot Licks Sep 12 '14 at 20:08
  • Also consider setting the locale as suggested in [Apple Technical Q&A 1480](https://developer.apple.com/library/ios/qa/qa1480/_index.html). – Rob Oct 22 '14 at 14:40