Categories
JavaScript Answers

How to get time in milliseconds in JavaScript?

Spread the love

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().

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *