Given a local timestamp and a UTC timestamp, is it possible to determine the timezone and whether DST is in effect?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your “UTC timestamp” is a float (int would suffice) of “seconds from the epoch”, and your “local timestamp” is some weird version of it shifted into your local time coordinates (there is no “epoch” except the UTC one), module time in the standard Python library suffices.
As these docs show, given “seconds from the epoch”,
gmtimetranslates that into a 9-items tuple in UTC,localtimeinto a 9-items tuple in local time; to go the other way around,calendar.timegm(UTC 9-items tuple to UTC timestamp) andmktime(local time 9-items tuple to UTC timestamp). You’ll note there’s no such thing as a “local timestamp” (only local time 9-items tuples akastruct_timeinstances), simply because no such concept exists.But, if I understand correctly what you mean by “local timestamp”, then translating it to a struct time “as if” it was a real timestamp, and then back into local time, will give the offset you seek (in seconds). As for DST, a bit telling whether it’s on is the 9th item of the tuples we’ve been mentioning.
For example, using the “local timestamp” only:
This says I’m 8 hours west of UTC. And:
this says that it is with DST in effect.