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=1331161200
&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):2024-11-09。
[null,null,["最后更新时间 (UTC):2024-11-09。"],[[["The Time Zone API provides time zone data, including UTC and daylight savings offsets, for specific locations based on latitude/longitude and timestamp."],["You can use the API to display localized time zone names, offsets, and enhance time-based data in your applications."],["The API accepts HTTPS requests with location and timestamp parameters and returns data in JSON or XML format."],["Client libraries are available in Java, Python, Go, and Node.js for easy integration into your projects."]]],["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"]]