// 获取当前时间戳的方法
// 方法一:使用 +new Date()
let timestamp1 = +new Date();
console.log(timestamp1); // 输出类似 1633072800000 的时间戳(毫秒)
// 方法二:使用 Date.now()
let timestamp2 = Date.now();
console.log(timestamp2); // 输出类似 1633072800000 的时间戳(毫秒)
// 如果需要获取秒级时间戳,可以除以 1000 并取整
let timestampInSeconds = Math.floor(Date.now() / 1000);
console.log(timestampInSeconds); // 输出类似 1633072800 的时间戳(秒)
+new Date():通过将 new Date() 转换为数字,可以直接获取当前时间的时间戳(单位为毫秒)。Date.now():这是获取当前时间戳的推荐方法,返回自 1970 年 1 月 1 日 00:00:00 UTC 到现在的毫秒数。Math.floor() 取整来实现。上一篇:vue换行符
下一篇:vue markdown插件
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站