Using python, what is the most accurate way to auto determine a users current timezone Using python, what is the most accurate way to auto determine a users current timezone flask flask

Using python, what is the most accurate way to auto determine a users current timezone


You could use Javascript and set the client's time zone in a cookie. You could even use an AJAX request and then send the offset to the server and save in the client's session.

var offset = new Date().getTimezoneOffset();

Description

The time-zone offset is the difference, in minutes, between UTC and local time. Note that>this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned. Daylight savings time prevents this value from being a constant even for a given locale

Mozilla Javascript Reference: getTimezoneOffset


If you can easily get the users' IP address from within flask (maybe from the request object?), you could use geolocation. E.g. via http://www.hostip.info/.

It is probably not 100% foolproof, though. For instance if someone uses a VPN or another kind of proxy you wouldn't see his "real" IP address.