Categories
JavaScript Answers

How to convert milliseconds to hours and minutes using Moment.js and JavaScript?

Spread the love

To convert milliseconds to hours and minutes using Moment.js and JavaScript, we use the duration method.

For instance, we write

const x = 433276000;
const tempTime = moment.duration(x);
const hours = tempTime.hours();
const minutes = tempTime.minutes();

to call duration with the number of milliseconds to convert it to a duration object.

Then we call hours to get the number of hours and minutes to get the number of minutes.

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 *