Skip to content

Instantly share code, notes, and snippets.

@nfreear
Forked from nithinbekal/wc10.html
Created October 5, 2011 09:11
Show Gist options
  • Save nfreear/1263992 to your computer and use it in GitHub Desktop.
Save nfreear/1263992 to your computer and use it in GitHub Desktop.
JavaScript Countdown timer / small / with fixes
<!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>
/*
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