Last active
December 3, 2020 10:07
-
-
Save software-mariodiana/9ecf61c104a033e2788ffd8fbbadae24 to your computer and use it in GitHub Desktop.
Date localization does unexpected things if all you're familiar with is U.S. dates.
This file contains 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
// iPhone settings: "Denmark" for region and "Buddhist" for calendar. | |
NSDate* now = [NSDate date]; | |
NSDateFormatter* df = [[NSDateFormatter alloc] init]; | |
df.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; | |
df.timeStyle = NSDateFormatterMediumStyle; | |
df.dateStyle = NSDateFormatterShortStyle; | |
// Date: 30/10/2563 BE, 14.32.18 | |
NSLog(@"Date: %@", [df stringFromDate:now]); | |
NSISO8601DateFormatter* isoDf = [[NSISO8601DateFormatter alloc] init]; | |
isoDf.formatOptions = NSISO8601DateFormatWithInternetDateTime; | |
// ISO Date: 2020-10-30T14:32:18Z | |
NSLog(@"ISO Date: %@", [isoDf stringFromDate:now]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment