Skip to content

Instantly share code, notes, and snippets.

@colormono
Forked from atinux/countdown.js
Last active December 19, 2015 02:38
Show Gist options
  • Save colormono/5883963 to your computer and use it in GitHub Desktop.
Save colormono/5883963 to your computer and use it in GitHub Desktop.
var countDown = function (endDate, el) {
el = el || $('body');
var leadingZero = function (nb) {
return (nb < 10) ? "0" + nb : + nb;
};
var updateTimer = function (seconds) {
var days = Math.floor(seconds / 86400);
seconds -= days * 86400;
var hours = Math.floor(seconds / 3600);
seconds -= hours * (3600);
var minutes = Math.floor(seconds / 60);
seconds -= minutes * (60);
//return ((days > 0) ? days + " days " : "") + leadingZero(hours) + ":" + leadingZero(minutes) + ":" + leadingZero(seconds);
return ((days > 0) ? days + " days" : "");
};
var tick = function () {
// Get seconds
var nbSeconds = parseInt((+endDate - +new Date) / 1000);
if (nbSeconds < 1) {
el.html('Time finished!');
return;
}
el.html(updateTimer(nbSeconds));
setTimeout(tick, 500);
};
tick();
};
countDown(new Date('2013-01-17T02:00:00'), $('#countdown'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment