javascript从epoch字符串转换为Date对象

时间:2021-04-03 11:28:02
var myDate = new Date();
var epoch = myDate.getTime(); //1318023197289 number of ms since epoch
var unixEpoch = Math.round(epoch/1000)
  1. How do you convert epoch back to a Date object?
  2. 如何将epoch转换回Date对象?
  3. Can you also convert unixEpoch back to a Date object?
  4. 你还可以将unixEpoch转换回Date对象吗?

1 个解决方案

#1


79  

var date = new Date(1318023197289);

And, since unixEpoch is simply epoch / 1000, you can similarly multiply the argument in the constructor by 1000.

并且,由于unixEpoch只是epoch / 1000,因此您可以将构造函数中的参数乘以1000。

#1


79  

var date = new Date(1318023197289);

And, since unixEpoch is simply epoch / 1000, you can similarly multiply the argument in the constructor by 1000.

并且,由于unixEpoch只是epoch / 1000,因此您可以将构造函数中的参数乘以1000。