hi,欢迎访问本站!
当前位置: 首页Web前端正文

js获取时间戳的几种方法

墨初 Web前端 356阅读

下面列出几种使用js脚本来获取时间戳的示例,精确到秒。

js获取时间戳的方法

方法1:

var timestamp = Date.parse(new Date());
console.log(timestamp);
// 1668414292000

方法2:

var timestamp = Math.round(new Date());
console.log(timestamp);
// 1668414292000

方法3:


var timestamp = (new Date()).valueOf();
console.log(timestamp);
// 1668414292000

方法4:

// 73so.com
var timestamp = new Date().getTime();
console.log(timestamp);
// 1668414292000

方法5:

var timestamp = +new Date();
console.log(timestamp);
// 1668414292000
声明:无特别说明,转载请标明本文来源!
相关推荐