[英]Get current time by city name
我試圖通過傳遞城市名稱來獲取當前日期和時間,我所能找到的只是通過時區或緯度和經度找到它。 誰能幫我實現這一目標?
您可以在World Clock Search API上創建Ajax請求。 比您在https://www.timeanddate.com/worldclock/germany/berlin上找回日期
如果您想要使用本機Javascript代碼顯示,請向我們顯示您已經擁有的內容。
太簡單了,您需要做的是:
1.從Google Maps API獲取城市名稱的經緯度
https://maps.googleapis.com/maps/api/geocode/json?&address=paris
2.在第一步中按給定緯度獲取時區
https://maps.googleapis.com/maps/api/timezone/json?location=43.29712312,5.382137115×tamp=1374868635&sensor=false
3.在第二步中通過給定的timeZoneId獲取dateTime
new Date().toLocaleString("en-US", {timeZone: "Europe/Paris"})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.