// 获取当前时间的时间戳(以毫秒为单位)
var now = new Date();
var timestamp = now.getTime();
console.log(timestamp); // 输出类似 1633072800000 的数字,表示自1970年1月1日以来的毫秒数
new Date()
创建一个表示当前日期和时间的 Date
对象。getTime()
方法返回从1970年1月1日 00:00:00 UTC到当前时间的毫秒数。这个值通常用于时间戳的计算或比较。如果你需要获取特定日期的时间戳,可以传递一个日期字符串或时间戳给 Date
构造函数,例如:
var specificDate = new Date('2023-10-01');
var timestamp = specificDate.getTime();
console.log(timestamp); // 输出对应于2023年10月1日的时间戳
上一篇:js 16进制转字符串
下一篇:js date format
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站