How to get time in milliseconds in JavaScript?

Sometimes, we want to get time in milliseconds in JavaScript.

In this article, we’ll look at how to get time in milliseconds in JavaScript.

How to get time in milliseconds in JavaScript?

To get time in milliseconds in JavaScript, we can use the + operator with new Date().

For instance, we write

const currentTime = +new Date();

to create a new Date object with the current date and time with new Date().

Then we convert the current date and time to the timestamp in milliseconds by putting + before it.

Conclusion

To get time in milliseconds in JavaScript, we can use the + operator with new Date().