How to convert hours and minutes to minutes with moment.js?

Sometimes, we want to convert hours and minutes to minutes with moment.js.

In this article, we’ll look at how to convert hours and minutes to minutes with moment.js.

How to convert hours and minutes to minutes with moment.js?

To convert hours and minutes to minutes with moment.js, we can use the duration and asMinutes methods.

For instance, we write:

const m = moment.duration(moment('10:10:10', 'HH:mm:ss').format("HH:mm")).asMinutes()
console.log(m)

We call moment.duration with a moment object formatted in HH:mm format to get the duration object.

Then we convert the duration to an object with the asMinutes methods.

Therefore, we get 610 as a the value of m.

Conclusion

To convert hours and minutes to minutes with moment.js, we can use the duration and asMinutes methods.