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:
xxxxxxxxxx
1
const getTimestamp = () => {
2
const now = Date.now();
3
return Math.floor(0.001 * now);
4
};
5
6
7
// Usage example:
8
9
const now = getTimestamp();
10
11
console.log(now); // 1639930461