0
我發現這個網址api-sunrise-sun sunset給出了UTC格式的日期時間,但是我想隨時轉換爲本地時間,而不管我的網頁在哪裏打開!我將如何實現這一目標?Json utc時間到當地時間
我發現這個網址api-sunrise-sun sunset給出了UTC格式的日期時間,但是我想隨時轉換爲本地時間,而不管我的網頁在哪裏打開!我將如何實現這一目標?Json utc時間到當地時間
我想你是在顯示成功獲取json之後的時間。試試這個:
//today's date, or whatever
var t_date = new Date().toLocaleDateString();
//time from json. example: 10:04:34 PM
var t_from_json = response["results"]["sunrise"]
var utc_date = new Date(t_date + " " + t_from_json + " UTC")
//Date 2017-02-21T22:04:34.000Z
//two options:
utc_date.toString();
//"Tue Feb 21 2017 19:04:34 GMT-0300 (CLST)"
var offset = new Date().getTimezoneOffset();
utc_date.setMinutes(utc_date.getMinutes() - offset);
//Date 2017-02-21T19:04:34.000Z
你試過簡單的$ .get嗎?順便說一下,它顯然不提供日期。 –