To get a UTC timestamp in JavaScript:

  1. Use the getTime() method of the Date object, e.g. new Date().getTime().
  2. The getTime() method returns the number of milliseconds since the Unix Epoch.
const timestamp = new Date().getTime()

console.log(timestamp) // 1662916646151

The getTime() method returns the number of milliseconds elapsed between January 1st, 1970, at 00:00:00 UTC and the specific date.

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.