Categories
JavaScript Answers

How to convert milliseconds into date and time with Moment.js and JavaScript?

Spread the love

Sometimes, we want to convert milliseconds into date and time with Moment.js and JavaScript.

In this article, we’ll look at how to convert milliseconds into date and time with Moment.js and JavaScript.

How to convert milliseconds into date and time with Moment.js and JavaScript?

To convert milliseconds into date and time with Moment.js and JavaScript, we use the format method.

For instance, we write

const dateTime = moment(1454521239279).format("DD MMM YYYY hh:mm a");

to call moment with the millisecond timestamp.

Then we call format to convert the timestamp into a string with the human readable date and time.

Conclusion

To convert milliseconds into date and time with Moment.js and JavaScript, we use the format method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.