How can I get seconds since epoch in Javascript?

后端 未结 10 738
野的像风
野的像风 2020-12-13 23:48

On Unix, I can run date \'+%s\' to get the amount of seconds since epoch. But I need to query that in a browser front-end, not back-end.

Is there a way

10条回答
  •  借酒劲吻你
    2020-12-14 00:05

    In chrome you can open the console with F12 and test the following code:

    var date = new Date().getTime()
    console.debug('date: ' + date);
    
    if (Date.now() < date)
        console.debug('ko');
    else
        console.debug('ok');
    

    https://www.eovao.com/en/a/javascript%20date/1/how-to-obtain-current-date-in-milliseconds-by-javascript-(epoch)

提交回复
热议问题