Skip to content

Instantly share code, notes, and snippets.

@reshadman
Created April 18, 2014 07:34
Show Gist options
  • Save reshadman/11029547 to your computer and use it in GitHub Desktop.
Save reshadman/11029547 to your computer and use it in GitHub Desktop.
Javascript Timer
var s=0;
var m=0;
var h=0;
setInterval(function(){elecTimerHandler()},1000);
function elecTimerHandler(){
s++;
if (s>59){
s = 0;
m++;
}
if (m>59){
m = 0;
h++;
}
if(h>23){
h=0;
}
console.log(lengthHandler(h) + ':' + lengthHandler(m) + ':' + lengthHandler(s));
return;
}
function lengthHandler(nom){
if (nom < 10){
nom = '0' + nom;
}
return nom;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment