11

This is a similar question as How to get the common name for a pytz timezone eg. EST/EDT for America/New_York , except I want to be able to just get a timezone from "PST" from pytz. such as tz = timezone("PST") Is this something like this possible with pytz?

Community
  • 1
  • 1
fangsterr
  • 3,670
  • 4
  • 37
  • 54

2 Answers2

3

I ended up just manually making a dictionary that mapped abbreviations to timezone names. For example, 'PST' : 'America/Los_Angeles' would be an entry (as would PDT for the daylight savings abbreviation).

fangsterr
  • 3,670
  • 4
  • 37
  • 54
  • 3
    Bad idea. Time zone abbreviations can be ambiguous. For example, there are 5 different meanings of "CST". [See Wikipedia's list of abbreviations](http://en.wikipedia.org/wiki/List_of_time_zone_abbreviations). – Matt Johnson-Pint Mar 26 '15 at 02:05
  • @MattJohnson thank you, this is helpful. I always thought it's unique! – marcadian Jun 16 '16 at 22:43
1

Have you tried using strptime with the %Z format code? I've never done it myself, but at least in theory you should be able to put in the tz code there and it should get translated into a tzinfo (embedded in the datetime/time object)

Daral
  • 26
  • 1
  • this would not resolve my issue. that would only get a constant offset. For example, PST and PDT would be translated to different offsets by %Z, but the datetime still not would be aware of the change to/from daylight savings time. – fangsterr Mar 18 '12 at 16:56