Skip to content

Instantly share code, notes, and snippets.

@IanKeen
Created August 13, 2015 15:46
Show Gist options
  • Save IanKeen/596d79c0c7719790d5af to your computer and use it in GitHub Desktop.
Save IanKeen/596d79c0c7719790d5af to your computer and use it in GitHub Desktop.
Example of displaying an NSDate in different timezones
NSDate *date = [NSDate date];
NSTimeZone *timeZoneCST = [NSTimeZone timeZoneWithAbbreviation:@"CST"];
NSTimeZone *timeZoneEST = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterShortStyle;
formatter.timeStyle = NSDateFormatterShortStyle;
formatter.timeZone = [NSTimeZone systemTimeZone];
NSLog(@"%@: %@", formatter.timeZone, [formatter stringFromDate:date]);
formatter.timeZone = timeZoneCST;
NSLog(@"%@: %@", formatter.timeZone, [formatter stringFromDate:date]);
formatter.timeZone = timeZoneEST;
NSLog(@"%@: %@", formatter.timeZone, [formatter stringFromDate:date]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment