Tổng quan về API múi giờ
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Time Zone API là dịch vụ chấp nhận yêu cầu HTTP
vĩ độ/kinh độ và ngày giờ đã chọn. Hàm này trả về thời gian
dữ liệu múi giờ cho vị trí, bao gồm cả độ lệch giờ UTC và giờ mùa hè
bất cứ lúc nào.
Lý do sử dụng API Múi giờ
Với Time Zone API, bạn có thể phát triển các ứng dụng cung cấp tên và mã múi giờ cho ngày và giờ tại các vị trí cụ thể trên bản đồ. Ví dụ: bạn có thể hiển thị như sau
dữ liệu múi giờ:
- Tên múi giờ đã bản địa hoá cho các vị trí trên bản đồ từ Nền tảng Google Maps.
- Chênh lệch múi giờ so với UTC và giờ mùa hè.
Dữ liệu múi giờ có thể đặc biệt hữu ích khi bạn muốn trang web hoặc ứng dụng hiển thị dữ liệu dựa trên thời gian phù hợp với người dùng.
Những việc bạn có thể làm với API Múi giờ
Với API Múi giờ, bạn có thể yêu cầu múi giờ cho các vị trí trên bề mặt trái đất, với độ lệch giờ so với UTC và giờ mùa hè cho từng vị trí đó.
Cách hoạt động của API Múi giờ
API Múi giờ chấp nhận yêu cầu HTTPS về toạ độ vĩ độ/kinh độ, ngày và giờ mong muốn dưới dạng dấu thời gian và tuỳ ý là mã ngôn ngữ. Phương thức này trả về dữ liệu ở định dạng do yêu cầu chỉ định.
Ví dụ sau đây minh hoạ yêu cầu cho
Nevada, Hoa Kỳ, với đầu ra được yêu cầu ở định dạng JSON.
https://maps.googleapis.com/maps/api/timezone/json
?location=39.6034810%2C-119.6822510
×tamp=1733428634
&key=YOUR_API_KEY
Tài nguyên
Bảng sau đây tóm tắt các tài nguyên có sẵn thông qua API Múi giờ cùng với dữ liệu mà API này trả về.
Tài nguyên dữ liệu |
Dữ liệu được trả về |
Định dạng trả về |
Múi giờ
Bạn cung cấp yêu cầu của mình cùng với vị trí và dấu thời gian. Xem
bắt buộc
tham số.
|
- Mã múi giờ.
- Tên múi giờ, có thể được bản địa hoá
- Mức chênh lệch so với giờ UTC, tính bằng giây
- Độ lệch cho giờ mùa hè, tính bằng giây
- Hãy xem phần Múi giờ để biết ví dụ cụ thể về phản hồi.
|
|
Cách sử dụng API Múi giờ
1 |
Thiết lập |
Hãy bắt đầu bằng việc Thiết lập
Dự án trên Google Cloud
và hoàn tất quá trình thiết lập
tiếp theo. |
2 |
Thử yêu cầu về múi giờ |
Sau khi có khoá API, bạn có thể bắt đầu thử nghiệm Time Zone API ngay từ
trình duyệt của bạn. Hãy xem Ví dụ về múi giờ trong hướng dẫn Yêu cầu và phản hồi về múi giờ để biết thông tin chi tiết.
|
3 |
Tìm hiểu thông tin cơ bản về câu trả lời |
Khám phá cách sử dụng dữ liệu múi giờ trong ứng dụng hoặc trang web của bạn.
Xem Phản hồi theo múi giờ
để biết thông tin chi tiết.
|
5 |
Tích hợp dữ liệu múi giờ vào ứng dụng của riêng bạn! |
Bạn có thể sử dụng dữ liệu múi giờ để cải thiện ứng dụng và trang web cho người dùng ở nhiều ngôn ngữ dựa trên múi giờ.
|
Các thư viện ứng dụng hiện có
Gọi API này bằng ngôn ngữ bạn chọn thông qua một trong các thư viện ứng dụng sau:
Ứng dụng Java, Ứng dụng Python, Ứng dụng Go và Ứng dụng Node.js cho Dịch vụ Maps của Google là các thư viện ứng dụng do cộng đồng hỗ trợ, nguồn mở theo Giấy phép Apache 2.0.
Tải các tệp đó xuống từ GitHub, nơi bạn cũng có thể tìm thấy hướng dẫn cài đặt và mã mẫu.
Các bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[[["\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)."]]