2025年01月25日 建站教程
前端开发一般都会用到时间戳,下面web建站小编给大家简单介绍获得时间戳的几种方法!
1、Date.now()方法(推荐)
var nowTime = Date.now() console.log('输出结果:', nowTime) //输出结果: 1679184802223
2、Date.parse()方法
var nowTime = Date.parse(new Date()) console.log('输出结果:', nowTime) //输出结果: 1679184844000
3、Date.getTime()方法
var date = new Date() var nowTime = date.getTime() console.log('输出结果:', nowTime) //输出结果: 1679184802223
4、+ new Date()方法
var nowTime = + new Date() console.log('输出结果:', nowTime) //输出结果: 1679184802223
本文链接:http://so.lmcjl.com/news/22003/