How to get a UTC timestamp in JavaScript

published: 26 Jul 2022

2 min read

How to get a UTC timestamp in JavaScript

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.

How to get a UTC timestamp in JavaScript | Coding Tips And Tricks

Are we missing something?  Help us improve this article. Reach out to us.

Are you looking for other code tips?

Check out what's on in the category: javascript, programming
Check out what's on in the tag: javascript, programming