Last active
August 29, 2015 14:11
-
-
Save wodim/aed9b4a107322b63f5da to your computer and use it in GitHub Desktop.
YASTHHMMSSF (Yet Another Seconds To HHMMSS Function)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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