Bogdan Laukhin Bogdan Laukhin - 1 year ago 112
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?

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download