给定UTC时间戳和UTC偏移量,是否可以在Python中获得时区? [英] Is it possible to get a timezone in Python given a UTC timestamp and a UTC offset?

查看:117
本文介绍了给定UTC时间戳和UTC偏移量,是否可以在Python中获得时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UTC偏移量和UTC时间的数据。鉴于此,是否有可能在Python中获取用户的本地时区(主要用于确定是否为DST等,可能使用pytz),类似于PHP timezone_name_from_abbr 中的函数?

I have data that is the UTC offset and the UTC time. Given that, is it possible in Python to get the user's local timezone (mainly to figure if it is DST etc. probably using pytz), similar to the function in PHP timezone_name_from_abbr?

例如:

如果我的纪元时间是1238720309,则
我可以得到UTC时间

If my epoch time is 1238720309, I can get the UTC time as:

>>> d = datetime.utcfromtimestamp(1238720309)
>>> print d + dt.timedelta(0,-28800) #offset for pacific I think
2009-04-02 17:04:41.712143 

这是正确的,除了现在是PDT,所以应该是:

This is correct except it is PDT right now, so it should be:

2009-04-02 18:04:41.712413

我需要获取在pytz中使用的时区

I need to get the timezone to use in pytz to figure out if it is daylight saving, I think?

推荐答案

因为通常,存在多个时区,在给定的时区偏移量下,通常的答案是不,不是没有更多信息。更多信息通常是时间所适用的位置-哪个国家,州或城市。

Since, in general, there is more than one possible time zone for a given time zone offset, the general answer is "No, not without more information". The more information is typically the location to which the time applies - which country, or state, or city.

这篇关于给定UTC时间戳和UTC偏移量,是否可以在Python中获得时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆