天气json转换时间Javascript时间戳

weather json convert time Javascript timestamp

本文关键字:Javascript 时间戳 时间 转换 json 天气      更新时间:2023-09-26

我从预报中获取天气json。IO和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},

要将时间戳转换为本地时区,

首先使用以下命令将时间戳改为日期:

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);
}