-
-
Save nfreear/1263992 to your computer and use it in GitHub Desktop.
JavaScript Countdown timer / small / with fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<meta charset="utf-8" /> | |
<title>Countdown Timer</title> | |
<div id="countdown_time"> </div> | |
<script src="wc10.js" type="text/javascript" charset="utf-8"></script> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code from javascript countdown timer example at: | |
http://nithinbekal.com/2009/12/06/javascript-how-to-create-a-simple-countdown-timer/ | |
*/ | |
function updateWCTime() { | |
function pad(num) { | |
return num > 9 ? num : '0'+num; | |
}; | |
// Declare local variables. | |
var | |
now = new Date(), | |
kickoff = Date.parse("October 16, 2011"), // Either new or .parse(), not both! | |
diff = kickoff - now, | |
days = Math.floor( diff / (1000*60*60*24) ), | |
hours = Math.floor( diff / (1000*60*60) ), | |
mins = Math.floor( diff / (1000*60) ), | |
secs = Math.floor( diff / 1000 ), | |
dd = days, | |
hh = hours - days * 24, | |
mm = mins - hours * 60, | |
ss = secs - mins * 60; | |
//console.log(diff); | |
// document.getElementById("countdown_time").innerHTML = dd + ' days<br/>' + hh + ' hours<br/>' + mm + ' minutes<br/>' + ss + ' seconds' ; | |
document.getElementById("countdown_time") | |
.innerHTML = | |
dd + ' days ' + | |
pad(hh) + ':' + //' hours ' + | |
pad(mm) + ':' + //' minutes ' + | |
pad(ss) ; //+ ' seconds' ; | |
} | |
setInterval('updateWCTime()', 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment