javascript 将纪元字符串转换为日期对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7693170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:12:14 来源:igfitidea点击:
javascript convert from epoch string to Date object
提问by fortuneRice
var myDate = new Date();
var epoch = myDate.getTime(); //1318023197289 number of ms since epoch
var unixEpoch = Math.round(epoch/1000)
- How do you convert
epoch
back to a Date object? - Can you also convert unixEpoch back to a Date object?
- 如何转换
epoch
回 Date 对象? - 您还可以将 unixEpoch 转换回 Date 对象吗?
回答by Matt
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。