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


基础教程推荐
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01