Getting current date in milliseconds (UTC) (NO use of strings)

前端 未结 5 2130
梦如初夏
梦如初夏 2021-02-18 18:35

Well, you might think that this question has already been asked, but I think it has not. The solutions I\'ve read about all had this \"jigsaw puzzle\" technique (like getU

5条回答
  •  甜味超标
    2021-02-18 19:25

    how about:

    var now = new Date();
    var utc_now = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
    console.log('UTC: ' + utc_now) // correct UTC time but wrong timezone!
    console.log('UTC (in ms): ' + utc_now.getTime())
    

提交回复
热议问题