Created
August 13, 2015 15:46
-
-
Save IanKeen/596d79c0c7719790d5af to your computer and use it in GitHub Desktop.
Example of displaying an NSDate in different timezones
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
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