Created
August 4, 2015 12:54
-
-
Save dodikk/b9f47e917a2ffdea263b to your computer and use it in GitHub Desktop.
NSDateFormatter bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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
Noon turned into midnight.