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.

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 *