Reputation:
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
?
For example:
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
This is correct except it is PDT right now, so it should be:
2009-04-02 18:04:41.712413
I need to get the timezone to use in pytz to figure out if it is daylight saving, I think?
Upvotes: 3
Views: 1812
Reputation:
No. Time zones are too complicated and there are too many that are X hours from UTC.
http://en.wikipedia.org/wiki/List_of_time_zones
For example, -5 from UTC could be Canada, New York, Cuba, Jamaica, Ecuador, etc.
The equator zones probably don't use DST since their day is roughly 12 hours year long. The south american ones, if they use some form of DST are probably on the opposite schedule of the north american ones because their summer/winter (i.e. short days/long days) schedules are also opposite.
Upvotes: 1
Reputation: 391820
No. http://en.wikipedia.org/wiki/List_of_U.S._states_by_time_zone
Upvotes: 0
Reputation: 753455
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.
Upvotes: 5