For example, how to convert this float number 6.5 to "06:30" using momentjs?
I've tried this:
moment("6.5", "hh:mm").format("HH:mm"))
but it outputs:
06:05
If you just need to convert your float
to string you can create a duration object and then display it as string using moment-duration-format plug-in.
Here a working example:
var dur = moment.duration(6.5, 'h');
console.log(dur.format('HH:mm'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-duration-format/1.3.0/moment-duration-format.min.js"></script>
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