Created
February 9, 2010 17:11
-
-
Save nithinbekal/299417 to your computer and use it in GitHub Desktop.
JavaScript Countdown timer
This file contains 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 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
<title>World Cup 2010 Countdown Timer</title> | |
</head> | |
<body> | |
<div id="worldcup_countdown_time"> </div> | |
<script src="wc10.js" type="text/javascript" charset="utf-8"></script> | |
</body> | |
</html> |
This file contains 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() { | |
now = new Date(); | |
kickoff = new Date.parse("June 11, 2010 11:30:00"); | |
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; | |
// document.getElementById("worldcup_countdown_time").innerHTML = dd + ' days<br/>' + hh + ' hours<br/>' + mm + ' minutes<br/>' + ss + ' seconds' ; | |
document.getElementById("worldcup_countdown_time") | |
.innerHTML = | |
dd + ' days ' + | |
hh + ' hours ' + | |
mm + ' minutes ' + | |
ss + ' seconds' ; | |
} | |
setInterval('updateWCTime()', 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 8 should be
kickoff = Date.parse("June 11, 2010 11:30:00");
; refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse