Given a pytz timezone for a particular user(calculated from his offset), i want to display the common name for that timezone. I'm assuming people are more accustomed to seeing EST or PST instead of spelled out like America/NewYork.
Does pytz give me those standard names somewhere, or will i have to manually do this via a table? This could potentially get messy, since for example places are EST in a season and shift to showing EDT during others.
pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime.
The method pytz. timezone() generates the current timezone of a particular region. Example 1: In the below program the current UTC time is converted according to Asia/Kolkata timezone.
Given a pytz timezone for a particular user(calculated from his offset), i want to display the common name for that timezone. I'm assuming people are more accustomed to seeing EST or PST instead of spelled out like America/NewYork.
If you need this derived from a datetime
object localized with pytz
...
>>> import pytz as tz >>> from datetime import datetime as dt >>> CT = tz.timezone('America/Chicago') >>> >>> summer_day = dt(2010, 7, 4, 0, 1, 1) >>> bar = CT.localize(summer_day, is_dst=None) >>> bar.tzname() 'CDT' >>> >>> christmas = dt(2010, 12, 25, 0, 1, 1) >>> foo = CT.localize(christmas, is_dst=None) >>> foo.tzname() 'CST' >>>
You can use the tzname()
method of tzinfo
instances:
>>> tz = timezone('America/St_Johns') >>> normal = datetime(2009, 9, 1) >>> tz.tzname(normal, is_dst=False) 'NDT'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With