Skip to content

Instantly share code, notes, and snippets.

@chrishulbert
Created May 13, 2011 01:33
Show Gist options
  • Select an option

  • Save chrishulbert/969812 to your computer and use it in GitHub Desktop.

Select an option

Save chrishulbert/969812 to your computer and use it in GitHub Desktop.
Current time in all timezones on an iphone
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