Last active
February 26, 2026 13:16
-
-
Save edwardabraham/8680198 to your computer and use it in GitHub Desktop.
Get a dictionary mapping timezone abbreviations to names, using pytz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ 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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 TimeandIndian Standard Timehave the same abbreviation,IST. So the dict looked like this:Just something to look out for.