// 获取当前时间的时间戳(以毫秒为单位)
let timestamp = Date.now();
console.log(timestamp); // 输出类似 1633072800000 的数字,表示自1970年1月1日以来的毫秒数
// 或者使用 new Date().getTime() 方法
let timestamp Alternative = new Date().getTime();
console.log(timestampAlternative); // 输出类似 1633072800000 的数字
// 将时间戳转换为日期对象
let date = new Date(timestamp);
console.log(date); // 输出类似 "2021-10-01T00:00:00.000Z" 的日期字符串
// 创建指定时间的日期对象并获取其时间戳
let specificDate = new Date('2021-10-01');
let specificTimestamp = specificDate.getTime();
console.log(specificTimestamp); // 输出 1633027200000
上一篇:js date格式化
下一篇:js format日期
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站