Skip to content

Instantly share code, notes, and snippets.

@iddqd3
Last active December 12, 2015 04:08
Show Gist options
  • Save iddqd3/4712266 to your computer and use it in GitHub Desktop.
Save iddqd3/4712266 to your computer and use it in GitHub Desktop.
Convert seconds to human readable format e.g. 67 = '00:01:07'
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;
}
@ukazap
Copy link

ukazap commented Feb 10, 2015

Thanks, works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment