Why NSDateFormatter can not parse date from ISO 8601 format [duplicate]

The problem is with the timezone on the end.

You need to either have it as: GMT-0X:00 or as -0X00 with no separate between hours and minutes.

The following two combinations work:

Combo 1 – use GMT format (GMT-0X:00) and ZZZZ

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZ"];
NSLog(@"DATE FORMAT:%@", [dateFormatter dateFromString:@"2008-12-29T00:27:42GMT-08:00"]);

Combo 2 – use RFC 822 format (-0X00) and ZZZ

dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSLog(@"DATE FORMAT:%@", [dateFormatter dateFromString:@"2008-12-29T00:27:42-0800"]);

Leave a Comment