我有 UTC 偏移量和 UTC 时间的数据。鉴于此,在 Python 中是否有可能获取用户的本地时区(主要是为了确定是否是 DST 等。可能使用 pytz),类似于 PHP 中的函数timezone_name_from_abbr
?
例如:
如果我的纪元时间是 1238720309,我可以得到 UTC 时间:
>>> d = datetime.utcfromtimestamp(1238720309)
>>> print d + dt.timedelta(0,-28800) #offset for pacific I think
2009-04-02 17:04:41.712143
这是正确的,只是现在是 PDT,所以它应该是:
2009-04-02 18:04:41.712413
我需要获取在 pytz 中使用的时区来确定它是否是夏令时,我想?