Skip to content

Instantly share code, notes, and snippets.

@software-mariodiana
Last active December 3, 2020 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save software-mariodiana/9ecf61c104a033e2788ffd8fbbadae24 to your computer and use it in GitHub Desktop.
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.
// 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