Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse ISO 8601 date in objective-c [duplicate]

I need to create an NSDate from json, and the date in in a format I have never used. The date string I'm getting back is 2014-02-07T03:10:43.824Z. Does anyone know the correct date format string I need to use for the date formatter?

like image 551
Chandler De Angelis Avatar asked Feb 07 '14 06:02

Chandler De Angelis


1 Answers

 NSDateFormatter *dateFormat = [NSDateFormatter new];
 //correcting format to include seconds and decimal place
 NSString* input = @"2014-02-07T03:10:59:434Z";
 dateFormat.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
 // Always use this locale when parsing fixed format date strings
 NSLocale* posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
 dateFormat.locale = posix;
 NSDate* output = [dateFormat dateFromString:input];
like image 95
Valentin Shamardin Avatar answered Nov 05 '22 04:11

Valentin Shamardin