// 将 JavaScript 日期对象转换为时间戳
// 创建一个 Date 对象,表示当前日期和时间
const date = new Date();
// 使用 getTime() 方法将日期对象转换为时间戳(以毫秒为单位)
const timestamp = date.getTime();
console.log("当前时间的时间戳(毫秒):", timestamp);
// 如果需要获取秒级时间戳,可以除以 1000 并取整
const timestampInSeconds = Math.floor(timestamp / 1000);
console.log("当前时间的时间戳(秒):", timestampInSeconds);
new Date():创建一个新的 Date 对象,表示当前的日期和时间。getTime():返回自 1970 年 1 月 1 日 00:00:00 UTC 到当前日期对象所表示的时间之间的毫秒数。Math.floor(timestamp / 1000):将毫秒级时间戳转换为秒级时间戳。上一篇:js 时间戳转成日期
下一篇:js 时间戳转日期
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站