compare timestamps in javascript

前端 未结 4 1650
攒了一身酷
攒了一身酷 2021-01-02 17:52

I have a date saved in a string with this format: 2017-09-28T22:59:02.448804522Z this value is provided by a backend service.

Now, in javascript how can

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 18:25

    You could also convert it to unix time in milliseconds:

    console.log(new Date('2017-09-28T22:59:02.448804522Z').valueOf())
    
    const currentTime = new Date('2017-09-28T22:59:02.448804522Z').valueOf()
        
    const expiryTime = new Date('2017-09-29T22:59:02.448804522Z').valueOf()
    
    if (currentTime < expiryTime) {
        console.log('not expired')
    }

提交回复
热议问题