<!-- Throw in a nice looking font just for the fun of it -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700,300,200"/>
<div class="cut main">
<h2>Code Snippet: Count Down</h2>
<div id="countdown">
<span class="days"><span></span> days</span>
<span class="hours"><span></span> hours</span>
<span class="minutes"><span></span> minutes</span>
<span class="seconds"><span></span> seconds</span>
</div>
</div>
/**
* The date when the countdown is to end - yyyy, mm, dd, hh, mm, ss
* Months: (Months start from 0)
* 0 == January 1 == February
* 2 == March 3 == April
* 4 == May 5 == June
* 6 == July 7 == August
* 8 == September 9 == October
* 10 == November 11 == December
**/
var end = new Date(2012, 10, 18, 21, 45, 00),
countdown = $('#countdown'),
days = countdown.find('.days span'),
hours = countdown.find('.hours span'),
minutes = countdown.find('.minutes span'),
seconds = countdown.find('.seconds span'),
set_count_down, time_loop;
set_count_down = function (){
var now = new Date(),
time_left = (end.getTime() - now.getTime()) / 1000,
d, h, m;
// any call back you want to put when the countdown finishes
if(time_left <= 0) {
clearInterval(time_loop);
window.location.reload();
return;
}
d = Math.floor(time_left/86400);
time_left -= d*86400;
h = Math.floor(time_left/3600);
time_left -= h*3600;
m = Math.floor(time_left/60);
time_left -= m*60;
days.html(d);
hours.html(h);
minutes.html(m);
seconds.html(Math.floor(time_left));
};
time_loop = setInterval(set_count_down, 1000);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.