How to get user's timezone

Hi there,

I would also recommend using an API! You can check out this tutorial for my Reverse Geocoding App - Get Location from Latitude/Longitude that uses the OpenCageData API. This tutorial will return the user’s country, but you can also get the user’s timezone.

This will be in the format:

"timezone" : {
               "name" : "America/Sao_Paulo",
               "now_in_dst" : 0,
               "offset_sec" : -10800,
               "offset_string" : "-0300",
               "short_name" : "BRT"
            },

Here is their description of the timezone property:

contains the keys name , now_in_dst , offset_sec , offset_string , short_name.
When the coordinates are in a country the name will be of the form Continent/City, the format used by tz database on *nix systems, for example Europe/Lisbon. When the coordinates are not in a country (for example in an ocean) the format will be an offset to/from GMT, for example GMT+2.
Learn more about timezones and how they are typically represented on *nix based systems over on Wikipedia.

I got this information from this web page: OpenCage Geocoding API Documentation

Hope that helps!

6 Likes