Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get pytz timezone from common abbreviation (PST, EST, etc.)?

Tags:

python

pytz

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?

like image 587
fangsterr Avatar asked Mar 17 '12 21:03

fangsterr


2 Answers

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).

like image 195
fangsterr Avatar answered Sep 26 '22 01:09

fangsterr


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)

like image 32
Daral Avatar answered Sep 23 '22 01:09

Daral