//(1)、精确到秒:
Date.parse(new Date()); //1570506183000
//(2)、精确到毫秒:
(new Date()).valueOf(); //1570506204713
//(3)、精确到毫秒:
new Date().getTime();//1570506204713
//(4)、JQuery获取时间戳
$.now(); //1570506204713
let timetamp = 1570511665;
let date = new Date(parseInt(timetamp) * 1000);
date.toDateString()
//"Tue Oct 08 2019"
date.toGMTString()
//"Tue, 08 Oct 2019 05:14:25 GMT"
date.toJSON()
//"2019-10-08T05:14:25.000Z"
date.toISOString();
//"2019-10-08T05:14:25.000Z"
date.toLocaleDateString()
//"2019/10/8"
date.toLocaleString("en-US", {hour12: false}).replace(/:\d{1,2}$/,' ')
//"10/8/2019, 13:14 " en-US设置为美国时区, hour12:false表示为24小时制
date.toString();
//"Tue Oct 08 2019 13:14:25 GMT+0800 (中国标准时间)"
date.toTimeString();
//"13:14:25 GMT+0800 (中国标准时间)"
date.toUTCString()
//"Tue, 08 Oct 2019 05:14:25 GMT"
上述是js提供的方法, 如果需要自定义格式,可以使用下面的函数
function formatDate(timestamp){
let time = new Date( Number(timestamp))
let year = time.getFullYear()
let month