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位
5.获取时间戳精确到毫秒,13位
const timestamp = +new Date();
console.log(timestamp);//输出 1591670099066 13位
时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
+new Date()
new Date().getTime()
Date.now()
时间戳主要用于清理缓存,大多数用于版本更新;