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); orxml, 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.timestampspecifies the desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses thetimestampto 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 toen.
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 specifiedtimestamp.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.OKindicates that the request was successful.INVALID_REQUESTindicates that the request was malformed.OVER_QUERY_LIMITindicates the requestor has exceeded quota.REQUEST_DENIEDindicates that the the API did not complete the request. Confirm that the request was sent over HTTPS instead of HTTP.UNKNOWN_ERRORindicates an unknown error.ZERO_RESULTSindicates 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 thanOK.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.
Request:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY
Response:
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
Request:
https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510×tamp=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.
Request:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331766000&key=YOUR_API_KEY
Response:
{
"dstOffset" : 3600,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Daylight Time"
}
Request:
https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510×tamp=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.
Request:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=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"
}
Request:
https://maps.googleapis.com/maps/api/timezone/xml?location=39.6034810,-119.6822510×tamp=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.
