Skip to content

Instantly share code, notes, and snippets.

@dodikk
Created August 4, 2015 12:54
Show Gist options
  • Save dodikk/b9f47e917a2ffdea263b to your computer and use it in GitHub Desktop.
Save dodikk/b9f47e917a2ffdea263b to your computer and use it in GitHub Desktop.
NSDateFormatter bug
NSLocale* posixLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US_POSIX"];
NSCalendar* gregorianCal = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
NSDateFormatter* df = [NSDateFormatter new];
{
gregorianCal.locale = posixLocale;
df.locale = posixLocale;
df.calendar = gregorianCal;
}
df.dateFormat = @"yyyy-MM-dd'T'hh:mm:ss.SSSZ";
NSDate* result = [df dateFromString: @"2015-08-04T12:02:09.280596Z"];
NSLog(@"%@", result); // 2015-08-04 00:02:09 +0000
@dodikk
Copy link
Author

dodikk commented Aug 4, 2015

Fixed by replacing hh ==> HH

df.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZ";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment