MrXXIV, on 10 October 2012 - 15:54, said:
Haha it's okay. Yea, I'm still in a confusion on it here. I'm definitely going to need some help on that and maybe writing commas on the view count to make it a little more readable.
here it is:
function formatDuration(duration){
//We only accept numbers
if(typeof duration != "number"){
return;
}
var pad = function(n){return n < 10 ? "0" + n : "" + n},
timeComponents = [], multiplier = 3600;
//Compute the value of each component (hours, minute, seconds)
for(; multiplier != 0; multiplier = parseInt(multiplier / 60)){
var component = parseInt(duration / multiplier);
duration %= multiplier;
//If hours equal to 0, do not add them.
if(multiplier == 3600 && component == 0){
continue;
}
timeComponents.push(component);
}
//Pad each component (2 -> 02)
for(var i = 0; i < timeComponents.length; i++){
var padded = pad(timeComponents[i]);
timeComponents[i] = padded;
}
return timeComponents.join(":");
}
tell me if you want some tweaks. It converts seconds to hours:minutes:seconds format, e.g. 51823 -> 14:23:43






