How to get a timestamp in milliseconds in JavaScript?

September 29, 2022 No comments timestamp js javascript milliseconds

Introduction

In JavaScript, we may wish to get a timestamp in milliseconds.

In this article, we'll look at how to get a timestamp in milliseconds in JavaScript.

How to get a timestamp in milliseconds in JavaScript

To get the timestamp in milliseconds since the Unix epoch, use Date.now() method:

console.log(Date.now());

The Date.now() method returns the number of milliseconds elapsed since January 1, 1970.

Conclusion

To get a timestamp in milliseconds in JS we can use Date.now() function.

If you want to get a timestamp in seconds simply divide Date.now() value by 1000.

{{ message }}

{{ 'Comments are closed.' | trans }}