Skip to content

Instantly share code, notes, and snippets.

@yyoshiki41
Created March 9, 2014 04:14
Show Gist options
  • Save yyoshiki41/9442845 to your computer and use it in GitHub Desktop.
Save yyoshiki41/9442845 to your computer and use it in GitHub Desktop.
function countdown();
function countDown() {
var startDateTime = new Date();
var endDateTime = new Date("March 9,2015 18:00:00");
var left = endDateTime - startDateTime;
var a_day = 24 * 60 * 60 * 1000;
var h = Math.floor((left % a_day) / (60 * 60 * 1000)),
m = Math.floor((left % a_day) / (60 * 1000)) % 60,
s = Math.floor((left % a_day) / 1000) % 60 % 60;
document.getElementById("#timer")[0].innerHTML = addZero(h) + ':' + addZero(m) + ':' + addZero(s);
setTimeout('countDown()', 1000);
}
function addZero(num) {
num = '00' + num;
str = num.substring( num.length - 2, num.length );
return str ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment