美文网首页js小知识
JS 格林威治时间转换为北京时间

JS 格林威治时间转换为北京时间

作者: 白菜_ud | 来源:发表于2021-01-19 11:48 被阅读0次

function TimeTrans(timestamp){

        let date = new Date(new Date(timestamp).getTime() + 8 * 3600 * 1000)

        date = date.toJSON();

        date = date.substring(0, 19).replace('T', ' ')

        return date 

}   

// 转换前 2021-01-19T02:25:40.783Z

//转换后 2021-01-19 10:25:40

相关文章

网友评论

    本文标题:JS 格林威治时间转换为北京时间

    本文链接:https://www.haomeiwen.com/subject/cbuavftx.html