NSTimezone get abbreviation from timezoneId
cocoa-touch, ios, timezone
Solution
The result of the `abbreviation` method seems to be locale dependent. If I set the region format to "United States", then your code actually returns "PST". If i set the region format to "Germany/German", it returns "GMT-8" (tested on the iOS Simulator).
But
[theTimezone localizedName:NSTimeZoneNameStyleShortStandard
locale:[NSLocale localeWithLocaleIdentifier:@"en_US"]]
gives "PST", independent of the region format.
(I am aware that this is only a partial solution. It returns the desired result only for American time zones. But perhaps it points into the right direction to solve the problem.)
Problem
In my IOS App I have a timezoneid like "America/Los_Angeles" and I would like to get its abbreviation "PST". I have written the following code: ``` NSTimeZone* theTimezone = [NSTimeZone timeZoneWithName:_timezone]; _timezoneAbbreviation = theTimezone.abbreviation; ``` My issue is `_timezoneAbbreviation` returns always a string like "UTC-x" or "UTC+x" instead of the appropriate abbreviation. If I'm looking in the `NSDictionary` returned by `[NSTimeZone abbreviations]` it contains the right abbreviation (for example PST for "America/Los_Angeles"). Any idea? Sebastien.