Last active
December 12, 2015 04:08
-
-
Save iddqd3/4712266 to your computer and use it in GitHub Desktop.
Convert seconds to human readable format e.g. 67 = '00:01:07'
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
function sec2humanReadable(duration){ | |
var hour = 0; | |
var min = 0; | |
var sec = 0; | |
if (duration){ | |
if (duration >= 60){ | |
min = Math.floor(duration / 60); | |
sec = duration % 60; | |
} | |
else{ | |
sec = duration; | |
} | |
if (min >= 60){ | |
hour = Math.floor(min / 60); | |
min = min - hour * 60; | |
} | |
if ( hour < 10 ){ hour = '0'+hour; } | |
if ( min < 10 ){ min = '0'+min; } | |
if ( sec < 10 ){ sec = '0'+sec; } | |
} | |
return hour +":"+ min +":"+ sec; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, works great.