How to get Unix Timestamp with JavaScript? [duplicate]

7

I've tried it here in some ways, but it seems to be wrong. An example of what I do:

var data = new Date();
var timestamp = data.getTime() / 1000;

Is this form correct?

    
asked by anonymous 12.02.2017 / 02:54

1 answer

7

Correct. Just missed rounding.

Timestamp in milliseconds:

+new Date() //que é o mesmo que new Date().getTime()

Timestamp in seconds:

Math.floor(+new Date() / 1000) //que o mesmo que Math.floor(new Date().getTime()/1000)
    
12.02.2017 / 03:19