Skip to content

Instantly share code, notes, and snippets.

@xianhuazhou
Created May 30, 2011 11:47
Show Gist options
  • Select an option

  • Save xianhuazhou/998780 to your computer and use it in GitHub Desktop.

Select an option

Save xianhuazhou/998780 to your computer and use it in GitHub Desktop.
// .........
// countDown(739209)
function countDown(time) {
var format = function(d) {
return d > 9 ? d : '0' + d;
}
var showUnit = function(d) {
return d != 1 ? 's' : '';
}
var container = $('#countDown');
function doCount() {
var d = format(parseInt(time / 86400));
var h = format(parseInt(time % 86400 / 3600));
var m = format(parseInt(time % 3600 / 60));
var s = format(time % 60);
container.html(
d + " Day" + showUnit(d) + " " +
h + " hour" + showUnit(h) + " " +
m + " minute" + showUnit(m) + " " +
s + " second" + showUnit(s) + ""
);
setTimeout(function(){
time--;
doCount()
}, 1000);
};
doCount();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment