You cannot use the seconds offset from GMT, alone, to uniquely determine the timezone abbreviation. There is not a one-to-one correspondence between offsets and timezones.
This probably isn't going to be satisfying, but you can get a list of matching timezones by iterating through the knownTimeZoneIdentifiers
and find a list of matching time zones:
let abbreviationsAndIdentifiers = TimeZone.knownTimeZoneIdentifiers
.compactMap { TimeZone(identifier: $0) }
.filter { $0.secondsFromGMT() == -28800 }
From there, you can use map
to grab either abbreviation(for:)
, identifier
or localizedName(for:locale:)
to get PST
, America/Los_Angeles
or Pacific Standard Time
for -28800
, respectively. Obviously, the above may return a variety of different matches depending on the offset and time of year.
A few caveats for future readers:
Timezone abbreviations are not unique. See https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations and you’ll see the same three letter abbreviation mapping to completely different time zones. E.g. CST
can mean “Central Standard Time” (in North America), “Cuba Standard Time” or “China Standard Time”.
Be wary about the fact that an offset from GMT of -28800
will result in different timezones depending upon the time of the year. E.g. -28800
will return one set of timezone matches in January and another set in July because of daylight savings. Consider using secondsFromGMT(for:)
, specifying the date, instead, to remove any ambiguity.