天气json转换时间Javascript时间戳

时间:2015-10-25 10:47:50

标签: javascript json

我从forecast.io获取天气json,在json数据中预测.io有时间戳:

 time:1445767494,"summary":"صافِ","icon":"clear-day","precipIntensity":0,"precipProbability":0,"temperature":32.99,"apparentTemperature":31.41,"dewPoint":10.56,"humidity":0.25,"windSpeed":3.51,"windBearing":256,"visibility":9,"cloudCover":0.22,"pressure":1012.37,"ozone":281.08},

想要将时间戳转换为loacl时区,

1 个答案:

答案 0 :(得分:0)

首先使用以下命令更改时间戳:

var x = new Date(1445767494);

然后使用下面的功能,您可以更改您的时区

    function toTimeZone(time, zone) {
    var format = 'YYYY/MM/DD HH:mm:ss ZZ';
    return moment(time, format).tz(zone).format(format);
}