Skip to content

Instantly share code, notes, and snippets.

@edwardabraham
Last active February 26, 2026 13:16
Show Gist options
  • Select an option

  • Save edwardabraham/8680198 to your computer and use it in GitHub Desktop.

Select an option

Save edwardabraham/8680198 to your computer and use it in GitHub Desktop.
Get a dictionary mapping timezone abbreviations to names, using pytz
""" Make a dictionary that maps timezone abbreviations to timezone names.
The timezone_lookup module supplies a single dictionary, timezone_lookup. For example,
>>> timezone_lookup['EST']
'US/Michigan'
"""
from datetime import datetime
import pytz
timezone_lookup = dict([(pytz.timezone(x).localize(datetime.now()).tzname(), x) for x in pytz.all_timezones])
@cserpell
Copy link

I found this searching a good way to get such a dictionary. Your solution actually does not work well, because of DST. It gets current available time zones in the world, but not time zones during other summer / winter season. You won't get all string that datetime may use.

@cheniel
Copy link

cheniel commented Oct 14, 2014

Not discounting the issue mentioned above, but you can combine this dictionary with the parsing method outlined here (replace TZINFOS) if you make a slight modification to line 12 to be:

tz_lookup = dict([(pytz.timezone(x).localize(datetime.now()).tzname(), pytz.timezone(x)) for x in pytz.all_timezones])

@pradeepcep
Copy link

One caveat, in case you found this through Google like I did:

Sometimes, timezones are overwritten in the resulting dict if they share the same abbreviation. For example, both Israel Standard Time and Indian Standard Time have the same abbreviation, IST. So the dict looked like this:

{
    ...

    'IST': 'Israel',  # Indian Standard Time, Asia/Kolkata not present!

    ...
}

Just something to look out for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment