Bogdan Laukhin Bogdan Laukhin - 4 months ago 27x
Objective-C Question

How to get GMT value for each timezone from knownTimeZoneNames

I know how to get the list of known timezones:

[NSTimeZone knownTimeZoneNames]

But this method returns only time zone names (like "Africa/Abidjan").

How can I get GMT value (like
)for each of known time zone from that array?


In general, create an NSTimeZone instance for each time zone name and then get the secondsFromGMT property from each instance:

for (NSString *name in [NSTimeZone knownTimeZoneNames]) {
    NSTimeZone *tz = [NSTimeZone timeZoneWithName:name];
    NSInteger gmtOffset = tz.secondsFromGMT;

The only outstanding issue would be converting from seconds to hours or hours/minutes, which shouldn't be too difficult. Perhaps the default [NSTimeZone description] would return the correct information?