Date object and the
getTime() method, which returns the number of milliseconds since January 1, 1970.
Here’s an example of how you can do this:
const timestamp = Math.floor(Date.now() / 1000); console.log(timestamp);
In the above example, the
Date.now() method returns the current time in milliseconds, which is then divided by 1000 to convert it to seconds. The result is then passed to the
Math.floor() function to round down to the nearest whole number.
The resulting 10-digit timestamp is stored in the
timestamp variable, which can be used as required. The value can also be logged to the console to check its value.