How can I determine the timezone of a website visitor?
Time zone data for an IP address is provided by several MaxMind products:
- All of the GeoIP2 Precision web services except Country provide the time zone in the location object of the returned JSON.
- The GeoIP2 City database similarly provides the time zone in the location record. To find out how to access this, refer to the documentation for your language’s GeoIP2 API.
- The GeoIP Legacy Insights web service provides the time zone as the tenth field returned.
- Although the GeoIP Legacy databases do not directly support time zones, some of the APIs provide the ability to look up the approximate time zone from the region and country for the IP address. In particular, the Legacy C, Java, PHP, Python, and Perl APIs support this.
All time zones provided by MaxMind are in the IANA time zone format (e.g., America/New_York).
Alternatively, you can use JavaScript to get the time zone offset of a visitor’s computer through the Date.prototype.getTimezoneOffset()
method.