Skip to content

Instantly share code, notes, and snippets.

@lexuschert
Created December 13, 2019 06:32
Show Gist options
  • Save lexuschert/a154303c4aebe44edf91b54fb22cb8f7 to your computer and use it in GitHub Desktop.
Save lexuschert/a154303c4aebe44edf91b54fb22cb8f7 to your computer and use it in GitHub Desktop.
formatTime
function formatTime(t) {
var res, sec, min, hour;
t = Math.max(t, 0);
sec = Math.round(t % 60);
res = (sec < 10) ? '0'+sec : sec;
t = Math.floor(t / 60);
min = t % 60;
res = min+':'+res;
t = Math.floor(t / 60);
if (t > 0) {
if (min < 10) res = '0' + res;
res = t+':'+res;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment