I was wondering if there's a simple way, using moment.js library, to transform a decimal time interval (for example, 1.074 minutes) into its equivalent 'mm:ss' value. I am currently using a function which doesn't work too well with negative times (it outputs the value in '-m:ss' format):
function secTommss(sec){
var min = Math.floor(sec/60)
sec = Math.round(Math.abs(sec) % 60);
return min + ":" + (sec < 10 ? "0" + sec : sec)
}
using just js, here's a really simple and fast way to do this for up to 12 hours:
Using moment:
Here is some JavaScript that will do what you are asking:
Examples:
You could use moment.js durations, such as
But currently, there's no clean way to format a duration in mm:ss like you asked, so you'd be re-doing most of that work anyway.