what is the best way to convert Hours Minutes to Decimal Time with momentjs
let say i have 1:30 min and i want to have 1.5 after the conversion
here is what i have tried
console.log(travelTime().split(':')[0]); return 1
console.log(travelTime().split(':')[1]); return 30 then / 30
where travelTime() == "1:30"
_i can also be undefined, in the case of creating the current moment with moment() . _d is the instance of the Date object that backs the moment object. If you are in "local mode", then _d will have the same local date and time as the moment object exhibits with the public API.
Try: moment({ // Options here }). format('HHmm') . That should give you the time in a 24 hour format.
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week.
Convert time If you want to create a moment object using current date and time, just call moment() without any arguments.
It looks like what you want is moment.duration(durationAsString)
to parse your duration and .asHours()
to format as decimal.
moment.duration('1:30').asHours();
will return 1.5
.
For more information, see Moment's documentation section on durations: http://momentjs.com/docs/#/durations/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With