Created by davebLinked to 91.6m issues across 63 teams
To get a timestamp in JavaScript, you can use the simple Date.now()
method. This method returns the number of milliseconds since the Unix epoch. You can also use the unary operator +
to call Date.prototype.valueOf
:
+ new Date()
Or, you can call valueOf
directly:
new Date().valueOf()
To get the number of seconds since the Unix epoch (i.e., Unix timestamp), you can use Math.floor(Date.now() / 1000)
. Alternatively, you can use bitwise-or to floor, which is slightly faster but less readable.
Date.now() / 1000 | 0