How can I get a timestamp in JavaScript?
Something similar to Unix timestamp, that is, a single number that represents the current time and date. Either as a number
The code Math.floor(new Date().getTime() / 1000)
can be shortened to new Date / 1E3 | 0
.
Consider to skip direct getTime() invocation and use | 0
as a replacement for Math.floor() function.
It's also good to remember 1E3
is a shorter equivalent for 1000
(uppercase E is preferred than lowercase to indicate 1E3
as a constant).
As a result you get the following:
var ts = new Date / 1E3 | 0;
console.log(ts);