Categories
JavaScript Answers

How to get current time in milliseconds with moment.js and JavaScript?

Spread the love

Sometimes, we want to get current time in milliseconds with moment.js and JavaScript.

In this article, we’ll look at how to get current time in milliseconds with moment.js and JavaScript.

How to get current time in milliseconds with moment.js and JavaScript?

To get current time in milliseconds with moment.js and JavaScript, we use the valueOf method.

For instance, we write

const timeInMilliseconds = moment().valueOf();

to call moment to return an moment object with the current datetime.

And then we call valueOf on it to return the timestamp of the current datetime in milliseconds.

Conclusion

To get current time in milliseconds with moment.js and JavaScript, we use the valueOf method.

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 *