如何获取pytz时区的通用名称,例如。美国东部/美国东部/纽约州纽约州 [英] How to get the common name for a pytz timezone eg. EST/EDT for America/New_York
问题描述
pytz在某处给我这些标准名称,还是我必须通过表手动执行此操作?这可能会变得凌乱,因为例如在一个季节中EST是EST,并在其他时段转向显示EDT。
给定特定用户的pytz时区(从他的偏移量计算),我想显示该时区的通用名称。我假设人们更习惯看到EST或PST,而不是像美国/纽约那样拼出。
如果你需要这个派生从 datetime
对象本地化与 pytz
...
>>>导入pytz为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'
>>>
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.
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'
>>>
这篇关于如何获取pytz时区的通用名称,例如。美国东部/美国东部/纽约州纽约州的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!