How to get a unix timestamp in JavaScript
To get a Unix timestamp in JavaScript, we need to add unary operator +
to the Date()
constructor.
Example:
const unix = + new Date();
console.log(unix); // 576366756374
To get the timestamp in milliseconds you can use:
const milliseconds = Math.floor(Date.now() / 1000);