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


- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01