How to get the common name for a pytz timezone eg. EST/EDT for America/New_York

后端 未结 4 1732
梦谈多话
梦谈多话 2020-12-09 14:40

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 see

4条回答
  •  既然无缘
    2020-12-09 15:09

    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'
    >>> 
    

提交回复
热议问题