获取时间戳

小董大咖 · 收录于 2023-09-24 03:56:02 · source URL

1.获取时间戳精确到秒,13位

const timestamp = Date.parse(new Date());
console.log(timestamp);
 
//输出 1591669256000   13位

2.获取时间戳精确到毫秒,13位

const timestamp = Math.round(new Date());
console.log(timestamp);
 
//输出 1591669961203   13位

3.获取时间戳精确到毫秒,13位

const timestamp = (new Date()).valueOf();
console.log(timestamp);
 
//输出 1591670037603   13位

4.或取时间戳精确到毫秒,13位

const timestamp = new Date().getTime();
console.log(timestamp);
 
//输出 1591670068833   13位