How to parse an ISO 8601 date in objective-c

I need to create an NSDate from json and a date in a format that I have never used. The date string I am returning is 2014-02-07T03:10:43.824Z. Does anyone know the correct date format string that I need to use to format the date?

+3
source share
1 answer
 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];
+11
source

All Articles