To get a UTC timestamp in JavaScript:
- Use the
getTime()
method of theDate
object, e.g.new Date().getTime()
. - 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.