【问题标题】:Django Pytz timezone full names with GMT value带有 GMT 值的 Django Pytz 时区全名
【发布时间】:2020-07-11 14:46:48
【问题描述】:

pytz 以 America/Chicago、America/Los_Angeles、Asia/Kolkata 或 tz 缩写等格式提供时区列表。

我想要时区 GMT 值的全名,如下所示

(GMT-11:00) Pacific/Pago_Pago

(GMT-07:00) America/Santa_Isabel

【问题讨论】:

    标签: python django timezone pytz


    【解决方案1】:

    我找到了解决方案。

    for timezone in pytz.common_timezones:
        tzone = pytz.timezone(timezone)
        std_date = None
    
        try:
            for utcdate, info in zip(tzone._utc_transition_times, tzone._transition_info):
            utcoffset, dstoffset, tzname = info
            if dstoffset == ZERO:
                std_date = utcdate
            if utcdate > NOW:
                break
        except AttributeError:
            std_date = NOW
    
        std_date = tzone.localize(std_date)  
        offset = std_date.strftime('%z')
        timezone_offset = "(GMT{0}:{1}){2}".format(offset[:-2],offset[-2:],timezone)
    

    【讨论】:

      猜你喜欢
      • 2015-07-30
      • 2011-04-29
      • 2018-10-20
      • 1970-01-01
      • 2021-09-14
      • 2012-07-25
      • 2012-12-01
      • 2017-09-05
      • 1970-01-01
      相关资源
      最近更新 更多