具有 GMT 值的 Django Pytz 时区全名

Django Pytz timezone full names with GMT value

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

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

(GMT-11:00) Pacific/Pago_Pago

(GMT-07:00) America/Santa_Isabel

这里我得到了解决方案。

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)