EN
JavaScript - get UNIX timestamp in seconds
4
points
In this short article, we would like to show how to get unix timstamp in seconds in JavaScript.
Note: as unix timestamp in this article we understans bash
date +%s
command result.
Quick solution:
// ONLINE-RUNNER:browser;
const getTimestamp = () => {
const now = Date.now();
return Math.floor(0.001 * now);
};
// Usage example:
const now = getTimestamp();
console.log(now); // 1639930461