@gabioh/tommss
Version:
Transform time to format HH:mm:ss
22 lines (18 loc) • 836 B
JavaScript
module.exports = {
toHhmmss: (time) => {
let secons = Number(time)
if (!secons) return "The value igresed is not valid";
let hh = Math.floor(secons / 3600);
let mm = Math.floor((secons - (hh * 3600)) / 60);
let ss = secons - (hh * 3600) - (mm * 60)
return `${hh >= 10 ? hh : '0' + hh }:${mm >= 10 ? mm : '0' + mm }:${ss >= 10 ? ss : '0' + ss}`;
},
toMmss: (time) => {
let secons = Number(time)
if (!secons) return "The value igresed is not valid";
let hh = Math.floor(secons / 3600);
let mm = Math.floor((secons - (hh * 3600)) / 60);
let ss = secons - (hh * 3600) - (mm * 60)
return `${hh > 0 ? hh >= 10 ? hh : '0' + hh + ":" :'' }${mm >= 10 ? mm : '0' + mm }:${ss >= 10 ? ss : '0' + ss}`;
}
}