简体   繁体   中英

javascript convert from epoch string to Date object

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. Can you also convert unixEpoch back to a Date object?
var date = new Date(1318023197289);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM