如何获取与当前时区对应的 tz_info 对象? [英] how to get tz_info object corresponding to current timezone?
本文介绍了如何获取与当前时区对应的 tz_info 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
python
(或pytz
)中是否有一个跨平台函数,它返回一个与当前设置的时区对应的tzinfo
对象电脑?
Is there a cross-platform function in python
(or pytz
) that returns a tzinfo
object corresponding to the timezone currently set on the computer?
环境变量不能依赖,因为它们不是跨平台的
environment variables cannot be counted on as they are not cross-platform
推荐答案
>>> import datetime
>>> today = datetime.datetime.now()
>>> insummer = datetime.datetime(2009,8,15,10,0,0)
>>> from pytz import reference
>>> localtime = reference.LocalTimezone()
>>> localtime.tzname(today)
'PST'
>>> localtime.tzname(insummer)
'PDT'
>>>
这篇关于如何获取与当前时区对应的 tz_info 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文