Skip to content

Instantly share code, notes, and snippets.

@jeystaats
Created February 24, 2017 15:53
Show Gist options
  • Save jeystaats/2130dc6d7424eb6904e3c9c51f61400b to your computer and use it in GitHub Desktop.
Save jeystaats/2130dc6d7424eb6904e3c9c51f61400b to your computer and use it in GitHub Desktop.
toHHMMSS(sec) {
let sec_num = parseInt(sec, 10); // don't forget the second parm
let hours = Math.floor(sec_num / 3600);
let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
let seconds = sec_num - (hours * 3600) - (minutes * 60);
let Ohours = hours + '';
let Ominutes = minutes + '';
let Oseconds = seconds + '';
if (hours < 10) {
Ohours = "0" + hours;
}
if (minutes < 10) {
Ominutes = "0" + minutes;
}
if (seconds < 10) {
Oseconds = "0" + seconds;
}
var time = Ohours + ':' + Ominutes + ':' + Oseconds;
return time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment