// 获取当前时间戳
let timestamp = Date.now();
console.log(timestamp); // 输出当前时间戳,单位为毫秒
// 或者使用 new Date().getTime()
let timestamp2 = new Date().getTime();
console.log(timestamp2); // 输出当前时间戳,单位为毫秒
// 如果需要获取秒级时间戳
let timestampInSeconds = Math.floor(Date.now() / 1000);
console.log(timestampInSeconds); // 输出当前时间戳,单位为秒
Date.now()
:这是获取当前时间戳最简单的方法,返回的是自1970年1月1日00:00:00 UTC到当前时间的毫秒数。new Date().getTime()
:这也是一个常用的方法,返回的结果与 Date.now()
相同,都是毫秒级的时间戳。上一篇:arttemplate vue
下一篇:vue3 学习
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站