Skip to main content
1 of 3

Your whole code can be reduced to this.

/* secsToDHMS()
 * Author Gary Green
 * http://stackoverflow.com/users/63523/gary-green
 */
function secsToDHMS(s)
{
  var x = [86400, 3600, 60, 1],z,i=-1;
  while (z=x[++i])
        x[i] = ("0" + parseInt(s / z,10)).slice(-2),
        s %= z;

    return x.join(':');
};


(function() {
    
    var currentDate      = new Date();
    var endDate          = new Date('March 30, 2012 18:10:00');
    var secsToGo         = (new Date(endDate - currentDate)).getTime() / 1000;
    var countdownElement = document.getElementById('countdown');
    
    var timer = setInterval(function() {
        
        if (! --secsToGo) clearInterval(timer);
       
        countdownElement.innerHTML = secsToDHMS(secsToGo);
        
    }, 1000);
    
})();

Fiddle: http://jsfiddle.net/xg63V/2