How to get the current timestamp in JavaScript?
JavaScript has a Date object that can be used to get the current timestamp. JavaScript date is fundamentally the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC.
There are a lot of different epoch out there. In JavaScript, the date and time are the same as the UNIX epoch.
The current timestamp can be fetched by calling the now() method on the Date object. We can get the current timestamp by calling the now() method on the Date object:
Date.now()
An alternative of the above now() method is the getTime method:
new Date().getTime()
We can do the following to get the current timestamp:
+new Date