How can I get seconds since epoch in Javascript?

后端 未结 10 753
野的像风
野的像风 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:13

    EPOCH means time from 01 January 1970
    var date = new Date();
    Following line will return the number of milliseconds from 01 Jaunary 1970
    var ms = date.getTime();
    Following line will convert milliseconds to seconds
    var seconds = Math.floor(ms/1000);
    console.log("Seconds since epoch =",seconds);
    

提交回复
热议问题