Skip to content

Instantly share code, notes, and snippets.

@wodim
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wodim/aed9b4a107322b63f5da to your computer and use it in GitHub Desktop.
Save wodim/aed9b4a107322b63f5da to your computer and use it in GitHub Desktop.
YASTHHMMSSF (Yet Another Seconds To HHMMSS Function)
var seconds_to_hhmmss = function(seconds) {
if (seconds < 0 || isNaN(seconds)) {
return "--:--";
}
var hh = (seconds / 3600);
hh = Math.floor(hh);
hh = hh < 10 ? "0" + hh : hh;
var mm = (seconds / 60) % 60;
mm = Math.floor(mm);
mm = mm < 10 ? "0" + mm : mm;
var ss = seconds % 60;
ss = Math.floor(ss);
ss = ss < 10 ? "0" + ss : ss;
if (hh >= 1) {
return hh + ":" + mm + ":" + ss;
} else if (mm >= 1) {
return mm + ":" + ss;
} else {
return "00:" + ss;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment