js常用的时间戳获取方式

220 阅读1分钟
    第一种方法:
    let timestamp = Date.parse(new Date())
    console.log('-----timestamp-----',timestamp)
    // 1671520872000  获取的时间戳会把毫秒改成000
    
    
    第二种方法:
    let timestamp = (new Date()).valueOf()
    console.log('-----timestamp-----',timestamp)
    // 1671520872123 获取当前毫秒级时间戳
    
    第三种方法:
    let timestamp = new Date().getTime()
    console.log('-----timestamp-----',timestamp)
    // 1671520872123 获取当前毫秒级时间戳