pytz提供美国/芝加哥,America / Los_Angeles,Asia / Kolkata或tz缩写等格式的时区列表 .
我想要时区的全名 .
中央标准时间
太平洋标准时间
印度标准时间
这在Python中可行吗?
Unicode CLDR project包含许多本地化字符串,包括许多不同语言的人类可读时区名称 .
快速搜索CLDR的Python实现the Babel library . 显示in this part of the documentation的示例如下:
>>> british = get_timezone('Europe/London') >>> format_datetime(dt, 'H:mm zzzz', tzinfo=british, locale='en_US') u'16:30 British Summer Time'
在这里我们可以看到 dt 变量指定的日期和时间,以及 Europe/London 的IANA时区(由pytz使用),英文显示名称为"British Summer Time" .
dt
Europe/London
还有一个如何获得通用时区名称的示例,而不考虑特定日期:
>>> from babel import Locale >>> from babel.dates import get_timezone_name, get_timezone >>> tz = get_timezone('Europe/Berlin') >>> get_timezone_name(tz, locale=Locale.parse('pt_PT')) u'Hor\xe1rio Alemanha'
也就是说, Europe/Berlin 时区的葡萄牙语名称为"Horário Alemanha" .
Europe/Berlin
见:Common time zone acronyms/abbreviations for use with the datetime_tz module
但是对于缩写的成绩单......你又是自己的 .
HTH
2 回答
Unicode CLDR project包含许多本地化字符串,包括许多不同语言的人类可读时区名称 .
快速搜索CLDR的Python实现the Babel library . 显示in this part of the documentation的示例如下:
在这里我们可以看到
dt
变量指定的日期和时间,以及Europe/London
的IANA时区(由pytz使用),英文显示名称为"British Summer Time" .还有一个如何获得通用时区名称的示例,而不考虑特定日期:
也就是说,
Europe/Berlin
时区的葡萄牙语名称为"Horário Alemanha" .见:Common time zone acronyms/abbreviations for use with the datetime_tz module
但是对于缩写的成绩单......你又是自己的 .
HTH