I am getting NSString 2012-08-17T10:56:45.508205 as time from Django API.
I am trying to convert that string into NSDate object with this code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate *date = [dateFormatter dateFromString:stringToConvert];
But date object is null. Where am I going wrong?
The ISO8601 string you’re getting from the Django API (2012-08-17T10:56:45.508205) does not include a time zone component. However, you are including that field symbol (Z) in your format string. Just remove that and it should work fine.
See the Unicode Technical Reference for more information on the formatting codes: