I have a simple script that increments every second and displays the total. Is it possible in JavaScript to just take that whole number and format it into time like hh:ii:ss?
function formatTime (seconds) {
//~~ does the same as Math.floor()
//Get full hours
var hours = ~~(seconds/3600);
//Get reminding seconds without hours
seconds = seconds % 3600;
//Same with minutes
var minutes = ~~(seconds/60);
seconds = seconds % 60;
//will use _f for formatting to convert 2 => 02, 12 => 12, etc.
//since we need 01:10:06 not 1:10:6
function _f (t) {
return (t < 10 ? '0' + t : t);
}
//Return hh:ii:ss
return _f(hours) + ':' + _f(minutes) + ':' + _f(seconds);
}