You're all set!

To start developing, please head over to our developer documentation.

Activate the Google Maps Time Zone API

To get you started we'll guide you through the Google Developers Console to do a few things first:

  1. Create or choose a project
  2. Activate the Google Maps Time Zone API
  3. Create appropriate keys
Continue

Developer's Guide

The Google Maps Time Zone API provides a simple interface to request the time zone for a location on the earth, as well as that location's time offset from UTC.

This service is also available in the Java, Python and Go client libraries.

This document is intended for website and mobile developers who want to include time data on maps provided by one of the Google Maps APIs. It provides an introduction to using the API and reference material on the available parameters.

Introduction

The Google Maps Time Zone API provides time offset data for locations on the surface of the earth. You request the time zone information for a specific latitude/longitude pair and date. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.

You access the Google Maps Time Zone API through an HTTPS interface.

Before you start developing with the Time Zone API, review the authentication requirements (you need an API key) and the API usage limits.

Time Zone Requests

Google Maps Time Zone API requests are constructed as a URL string. The API returns time zone data for a point on the earth, specified by a latitude/longitude pair. Note that time zone data may not be available for locations over water, such as oceans or seas.

A Google Maps Time Zone API request takes the following form:

https://maps.googleapis.com/maps/api/timezone/outputFormat?parameters

where outputFormat may be either of the following values:

  • json (recommended), indicates output in JavaScript Object Notation (JSON); or
  • xml, indicates output in XML, wrapped within a <TimeZoneResponse> node.

Important: You must submit requests via https, not http.

Note: URLs must be properly encoded to be valid and are limited to 2048 characters for all web services. Be aware of this limit when constructing your URLs. Note that different browsers, proxies, and servers may have different URL character limits as well.

Request Parameters

As is standard in all URLs, parameters are separated using the ampersand (&) character. The list of parameters and their possible values are denoted below.

Required Parameters

  • location: a comma-separated lat,lng tuple (eg. location=-33.86,151.20), representing the location to look up.
  • timestamp specifies the desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values.
  • key — Your application's API key. This key identifies your application for purposes of quota management. Learn how to get a key.

    Note: Google Maps APIs Premium Plan customers may use either an API key, or a valid client ID and digital signature, in your Time Zone requests. Get more information on authentication parameters for Premium Plan customers.

Optional Parameters

  • language — The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. Defaults to en.

Time Zone Responses

For each valid request, the time zone service will return a response in the format indicated within the request URL. Each response will contain the following elements:

  • dstOffset: the offset for daylight-savings time in seconds. This will be zero if the time zone is not in Daylight Savings Time during the specified timestamp.
  • rawOffset: the offset from UTC (in seconds) for the given location. This does not take into effect daylight savings.
  • timeZoneId: a string containing the "tz" ID of the time zone, such as "America/Los_Angeles" or "Australia/Sydney". These IDs are defined in the IANA Time Zone Database, which is also available in searchable format in Wikipedia's List of tz database time zones.
  • timeZoneName: a string containing the long form name of the time zone. This field will be localized if the language parameter is set. eg. "Pacific Daylight Time" or "Australian Eastern Daylight Time"
  • status: a string indicating the status of the response.
    • OK indicates that the request was successful.
    • INVALID_REQUEST indicates that the request was malformed.
    • OVER_QUERY_LIMIT indicates the requestor has exceeded quota.
    • REQUEST_DENIED indicates that the the API did not complete the request. Confirm that the request was sent over HTTPS instead of HTTP.
    • UNKNOWN_ERROR indicates an unknown error.
    • ZERO_RESULTS indicates that no time zone data could be found for the specified position or time. Confirm that the request is for a location on land, and not over water.
  • error_message: more detailed information about the reasons behind the given status code, if other than OK.

    Note: This field is not guaranteed to be always present, and its content is subject to change.

Calculating the Local Time

The local time of a given location is the sum of the timestamp parameter, and the dstOffset and rawOffset fields from the result.

Example Requests

This section includes some sample queries that demonstrate features of the API.

The below query performs a time zone request for Nevada, USA. The timestamp is set to March 8th, 2012.

JSON

Request:

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY

Response:

{
   "dstOffset" : 0,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Standard Time"
}
    
XML

Request:

https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY

Response:

<TimeZoneResponse>
  <status>OK</status>
  <raw_offset>-28800.0000000</raw_offset>
  <dst_offset>0.0000000</dst_offset>
  <time_zone_id>America/Los_Angeles</time_zone_id>
  <time_zone_name>Pacific Standard Time</time_zone_name>
</TimeZoneResponse>

The below query performs a time zone request for Nevada, USA. The location is the same as the above request, but the timestamp is set to March 15th, 2012. The response now includes a Daylight Savings Time offset.

JSON

Request:

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&key=YOUR_API_KEY

Response:

{
   "dstOffset" : 3600,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Pacific Daylight Time"
}
    
XML

Request:

https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510&timestamp=1331766000&key=YOUR_API_KEY

Response:

<TimeZoneResponse>
  <status>OK</status>
  <raw_offset>-28800.0000000</raw_offset>
  <dst_offset>3600.0000000</dst_offset>
  <time_zone_id>America/Los_Angeles</time_zone_id>
  <time_zone_name>Pacific Daylight Time</time_zone_name>
</TimeZoneResponse>

This example is similar to the above two, but sets a language parameter. The response will now be localized to Spanish.

JSON

Request:

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331766000&language=es&key=YOUR_API_KEY

Response:

{
   "dstOffset" : 3600,
   "rawOffset" : -28800,
   "status" : "OK",
   "timeZoneId" : "America/Los_Angeles",
   "timeZoneName" : "Hora de verano del Pacífico"
}
    
XML

Request:

https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510&timestamp=1331766000&language=es&key=YOUR_API_KEY

Response:

<TimeZoneResponse>
  <status>OK</status>
  <raw_offset>-28800.0000000</raw_offset>
  <dst_offset>3600.0000000</dst_offset>
  <time_zone_id>America/Los_Angeles</time_zone_id>
  <time_zone_name>Hora de verano del Pacífico</time_zone_name>
</TimeZoneResponse>

The sensor Parameter

The Google Maps API previously required that you include the sensor parameter to indicate whether your application used a sensor to determine the user's location. This parameter is no longer required.

Send feedback about...

Google Maps Time Zone API
Google Maps Time Zone API
Need help? Visit our support page.