published: 26 Jul 2022
2 min read
How to get a UTC timestamp in JavaScript
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.
Are we missing something? Help us improve this article. Reach out to us.
How to get a UTC timestamp in JavaScript
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.
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
JS Nooby
Javascript connoisseur