// 获取当前时间戳(以毫秒为单位)
let timestamp = Date.now();
console.log(timestamp); // 输出类似 1633047600123 的数字,表示自1970年1月1日以来的毫秒数
// 或者使用 new Date().getTime() 方法
let timestampAlt = new Date().getTime();
console.log(timestampAlt); // 输出与上面相同的时间戳
// 如果需要获取秒级时间戳(以秒为单位),可以将毫秒时间戳除以1000并取整
let timestampInSeconds = Math.floor(Date.now() / 1000);
console.log(timestampInSeconds); // 输出类似 1633047600 的数字,表示自1970年1月1日以来的秒数
上一篇:js tcp
下一篇:js 当前时间戳
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站