Time Zone API 概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Time Zone API 是一项服务,可接受
纬度/经度坐标以及选定的日期和时间。它会返回
该位置的时区数据,包括世界协调时间 (UTC) 和夏令时的偏移量
。
为何使用 Time Zone API
借助时区 API,您可以开发应用,以便为地图上特定位置的日期和时间提供时区 ID 和名称。例如,您可以向
时区数据:
- Google Maps Platform 中地图位置的本地化时区名称。
- 时区偏离世界协调时间 (UTC) 和夏令时。
如果您希望网站或应用显示与用户相关的时间数据,时区数据会特别有用。
Time Zone API 的用途
利用 Time Zone API,您可以请求获取
地球表面的位置,以相对于
UTC 和夏令时
这些地理位置
Time Zone API 的运作方式
时区 API 接受包含纬度/经度坐标、所需日期和时间(作为时间戳)以及可选语言代码的 HTTPS 请求。该方法以请求指定的格式返回数据。
以下示例显示了针对美国内华达州的请求,其中请求的输出采用 JSON 格式。
https://maps.googleapis.com/maps/api/timezone/json
?location=39.6034810%2C-119.6822510
×tamp=1733428634
&key=YOUR_API_KEY
资源
下表汇总了通过 Time Zone API 提供的资源以及该 API 返回的数据。
数据资源 |
返回的数据 |
返回格式 |
时区
您提供请求以及位置和时间戳。请参阅
必需
参数。
|
- 时区 ID。
- 时区名称(可选择本地化)
- 世界协调时间 (UTC) 的偏移量(以秒为单位)
- DST 的偏移量(以秒为单位)
- 如需查看具体响应示例,请参阅时区。
|
|
如何使用 Time Zone API
1 |
开始设置 |
首先设置 Google Cloud 项目,然后完成后续的设置说明。 |
2 |
尝试时区请求 |
获得 API 密钥后,您就可以直接在浏览器中开始测试 Time Zone API。如需了解详情,请参阅时区请求和响应指南中的时区示例。
|
3 |
了解响应基础知识 |
了解如何在应用或网站中使用时区数据。
请参阅时区响应
了解详情。
|
5 |
将时区数据纳入到您自己的应用中! |
您可以使用时区数据来为以下国家/地区的用户改进应用和网站
基于时间的不同语言区域。
|
可用的客户端库
通过以下任一客户端库以您偏好的语言调用此 API:
适用于 Google 地图服务的 Java 客户端、Python 客户端、Go 客户端和 Node.js 客户端是由社区提供支持的客户端库,并且根据 Apache 2.0 许可开放源代码。您可以从 GitHub 下载它们,您还可以在 GitHub 上找到安装说明和示例代码。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe Time Zone API provides time zone data, including UTC and daylight savings offsets, for specific locations based on latitude/longitude and timestamp.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the API to display localized time zone names, offsets, and enhance time-based data in your applications.\u003c/p\u003e\n"],["\u003cp\u003eThe API accepts HTTPS requests with location and timestamp parameters and returns data in JSON or XML format.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries are available in Java, Python, Go, and Node.js for easy integration into your projects.\u003c/p\u003e\n"]]],["The Time Zone API retrieves time zone data for specific locations using latitude/longitude coordinates and a timestamp. It returns the time zone ID, localized name, UTC offset, and daylight saving time offset in JSON or XML format. To use it, you send an HTTPS request with location and timestamp and you can then utilize the data in your website or apps to show time-based information relevant to users' locations. You can also use one of the provided client libraries to access the API.\n"],null,["# Time Zone API overview\n\nThe Time Zone API is a service that accepts an HTTP request of\nlatitude/longitude coordinates and a chosen date and time. It returns the time\nzone data for the location, including offsets for UTC and daylight savings\ntime.\n\nWhy use the Time Zone API\n-------------------------\n\nWith the Time Zone API, you can develop applications that provide\nthe time zone ID and name for dates and times at specific locations\non a map. For example, you can show the following\ntime zone data:\n\n- Localized time zone names for map locations from the Google Maps Platform.\n- Time zone offsets from UTC and for daylight savings.\n\nTime zone data can be particularly useful when you want to have your\nwebsite or app display time-based data relevant to your users.\n\nWhat you can do with the Time Zone API\n--------------------------------------\n\nWith the Time Zone API, you can request the time zone for\nlocations on the surface of the earth, with the time offset from\nUTC and for daylight savings time for each of\nthose locations.\n\nHow the Time Zone API works\n---------------------------\n\nThe Time Zone API accepts an HTTPS request of latitude/longitude\ncoordinates, the desired date and time as a timestamp, and optionally,\na language code. It returns data in the format specified by the request.\nThe following example shows a request for\nNevada, USA, with a requested output in JSON. \n\n```scdoc\n https://maps.googleapis.com/maps/api/timezone/json\n ?location=39.6034810%2C-119.6822510\n ×tamp=1733428634\n &key=YOUR_API_KEY\n \n```\n\n### Resources\n\nThe following table summarizes the resources available through the\nTime Zone API along with the data it returns.\n\n| Data resources | Data returned | Return format |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|\n| **Timezone** You provide your request along with location and timestamp. See [required parameters](/maps/documentation/timezone/requests-timezone#required-parameters). | - Time zone ID. - Time zone name, optionally localized - Offset from UTC, in seconds - Offset for DST, in seconds - See Time Zone for specific response examples. | - JSON - XML |\n\nHow to use the Time Zone API\n----------------------------\n\n|---|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | **Get set up** | Start with [Set up your Google Cloud project](/maps/documentation/elevation/cloud-setup) and complete the setup instructions that follow. |\n| 2 | **Try a timezone request** | Once you have an API key, you can start testing out the Time Zone API directly from your browser. See [Time Zone examples](/maps/documentation/timezone/requests-timezone#examples) in the Timezone requests and responses guide for details. |\n| 3 | **Understand response basics** | Explore how to use timezone data in your app or website. See [Time Zone responses](/maps/documentation/timezone/requests-timezone#responses) for details. |\n| 5 | **Incorporate timezone data into your own app!** | You can use timezone data to enhance apps and websites for users across different time-based locales. |\n\n### Available client libraries\n\nCall this API in the language of\nyour choice through one of the following client libraries:\n\n- [Java\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-java)\n- [Python\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-python)\n- [Go Client\n for Google Maps Services](https://github.com/googlemaps/google-maps-services-go)\n- [Node.js\n Client for Google Maps Services](https://github.com/googlemaps/google-maps-services-js)\n\nThe Java Client, Python Client, Go Client and Node.js Client for Google Maps\nServices are community-supported client libraries, open sourced under the\n[Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).\nDownload them from GitHub, where you can also find installation instructions and sample code.\n\nWhat's next\n-----------\n\n- **Learn how to make Time Zone requests** : Go to [Time Zone Requests and responses](/maps/documentation/timezone/requests-timezone).\n- **Follow best practices** : Go to [Web Services Best Practices](/maps/documentation/timezone/web-service-best-practices)."]]