// 生成时间戳的示例代码
// 方法1: 使用 Date.now()
let timestamp1 = Date.now();
console.log("当前时间戳 (毫秒):", timestamp1);
// 解释: Date.now() 返回自1970年1月1日00:00:00 UTC到当前时间的毫秒数。
// 方法2: 使用 new Date().getTime()
let timestamp2 = new Date().getTime();
console.log("当前时间戳 (毫秒):", timestamp2);
// 解释: new Date().getTime() 与 Date.now() 类似,返回自1970年1月1日00:00:00 UTC到当前时间的毫秒数。
// 方法3: 获取秒级时间戳
let timestamp3 = Math.floor(Date.now() / 1000);
console.log("当前时间戳 (秒):", timestamp3);
// 解释: 通过将毫秒时间戳除以1000并取整,可以得到秒级时间戳。
上一篇:js substring()用法
下一篇:js 获取 url 参数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站