To generate timestamp unix epoch format with Node.js, we use the Date
constructor.
For instance, we write
const ts = Math.floor(new Date().getTime() / 1000);
to create a new date with the current date and time with the Date
constructor.
Then we call getTime
to get its timestamp in milliseconds.
And then we divide that by 1000 to get the timestamp in seconds.
Finally, we call Math.floor
with the timestamp in seconds to round it down to the nearest integer.