js 时间戳的生成方法

生成的都是 13 位的时间戳。
通过多次测试 Date.parse(new Date()) 返回的13位时间戳 后3位总是000 只能精确到秒 
使用:
var timestamp3 = new Date().getTime() 方法即可

js 生成时间戳方法
js 生成时间戳方法

                                                                         

var timestamp1 = Date.parse(new Date())

var timestamp2 = (new Date()).valueOf()

var timestamp3 = new Date().getTime()

var timestamp4 = Date.now()

var timestamp5 = +new Date()

console.log('timestamp1>>>',timestamp1)
console.log('timestamp1>typeof>>', typeof timestamp1)
console.log('timestamp2>>>',timestamp2)
console.log('timestamp2>typeof>>', typeof timestamp2)
console.log('timestamp3>>>',timestamp3)
console.log('timestamp3>typeof>>', typeof timestamp3)
console.log('timestamp4>>>',timestamp4)
console.log('timestamp4>typeof>>', typeof timestamp4)
console.log('timestamp5>>>',timestamp5)
console.log('timestamp5>typeof>>', typeof timestamp5)




猜你喜欢

转载自blog.csdn.net/qq_33650655/article/details/91863840
今日推荐