I need to convert hours and minutes in minutes values. With pure JavaScript Date object I do the following:
var d = new Date();
var minutes = d.getHours() * 60 + d.getMinutes();
I've just switched to moment.js and looking for better solution likes the following:
var minutes = moment(new Date()).toMinutes()
Is there is something like this?
I didn't needed moment.js, at least worked for my scenarios:
I think your best bet is to create a
Duration
and then get the minutes usingasMinutes
. This is probably clearer when describing an interval of time.Here is the reference in the docs.
You could use:
http://momentjs.com/docs/#/get-set/minute/
For those seeking to get minutes from an existing
Moment
object, you can first format it to whatever you need, then useduration
to get its duration in minutes: