Google Time Zone API (Python)

April 3, 2020

Install

pip install -U googlemaps

Enable API

Enable Time Zone API at Google Cloud Console.

API Key

Create API Key at Google Cloud Console -> Credentials

  • Create credentials -> API Key (Copy API Key)
  • Restrict API Key (Optional): Select Restrict Key and select Time Zone API.

Code

import googlemaps

GOOGLE_API_KEY = ...
location = '41.732438,44.7688135'
timestamp = None # optional

gmaps = googlemaps.Client(key=GOOGLE_API_KEY)

try:
    result = gmaps.timezone(location=location, timestamp=timestamp)
except Exception as e:
    log.error(e)

Sample Result

{
    "dstOffset": 0,
    "rawOffset": 14400,
    "status": "OK",
    "timeZoneId": "Asia/Tbilisi",
    "timeZoneName": "Georgia Standard Time"
}

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.