Created
May 13, 2011 01:33
-
-
Save chrishulbert/969812 to your computer and use it in GitHub Desktop.
Current time in all timezones on an iphone
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
| NSCalendar *cal = [[NSCalendar alloc] | |
| initWithCalendarIdentifier:NSGregorianCalendar]; | |
| for (NSString *tzName in [NSTimeZone knownTimeZoneNames]) { | |
| cal.timeZone = [NSTimeZone timeZoneWithName:tzName]; | |
| int whichComponents = NSDayCalendarUnit | NSMonthCalendarUnit | | |
| NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit; | |
| NSDateComponents *components = [cal components:whichComponents | |
| fromDate:[NSDate date]]; | |
| NSLog(@"Time in %@: %d-%d-%d %d:%d", | |
| tzName, components.year, components.month, components.day, | |
| components.hour, components.minute); | |
| } | |
| [cal release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment