How do you convert Milliseconds into a Javascript UTC date?

前端 未结 3 1947
不知归路
不知归路 2021-01-06 00:09

Given I have the number 1446309338000, how do I create a JavaScript UTC date?

new Date(1446309338000) will equal a CST time (central standa

3条回答
  •  时光说笑
    2021-01-06 00:25

    Well, if the date string is what you require, hope this helps:

    new Date(1446309338000).toLocaleString('en-US', {timeZone: 'UTC'})
    

    As far as toISOString() is concerned, it returns string representation using ISO-8601 standard (the format is: YYYY-MM-DDTHH:mm:ss.sssZ).
    toLocaleString() is human readable format with same result.

提交回复
热议问题