Skip to main content
Code Review

Return to Answer

added 361 characters in body
Source Link

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 2330, 2012 2218:4210:30'00');
 var secsToGo = (new Date(endDate - currentDate)).getTime() / 1000;
 var countdownElement = document.getElementById('countdown');
 
 var timer = setInterval(function() {
 
 if (--secsToGo < 0) {
 clearInterval(timer);
 return;
 }
 
 countdownElement.innerHTML = secsToDHMS(secsToGo);
 
 }, 1000);
 
})();

Fiddle: http://jsfiddle.net/xg63V/3 http://jsfiddle.net/xg63V/4


Compressed version 311 bytes

(function(){var d=(new Date(new Date("March 30, 2012 18:10:00")-new Date)).getTime()/1E3,
f=document.getElementById("countdown"),g=setInterval(function(){if(0>--d)clearInterval(g);
else{for(var a=d,b=[86400,3600,60,1],c,e=-1;c=b[++e];)b[e]=("0"+parseInt(a/c,10)).slice(-2),
a%=c;f.innerHTML=b.join(":")}},1E3)})();​

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 23, 2012 22:42:30');
 var secsToGo = (new Date(endDate - currentDate)).getTime() / 1000;
 var countdownElement = document.getElementById('countdown');
 
 var timer = setInterval(function() {
 
 if (--secsToGo < 0) {
 clearInterval(timer);
 return;
 }
 
 countdownElement.innerHTML = secsToDHMS(secsToGo);
 
 }, 1000);
 
})();

Fiddle: http://jsfiddle.net/xg63V/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 < 0) {
 clearInterval(timer);
 return;
 }
 
 countdownElement.innerHTML = secsToDHMS(secsToGo);
 
 }, 1000);
 
})();

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


Compressed version 311 bytes

(function(){var d=(new Date(new Date("March 30, 2012 18:10:00")-new Date)).getTime()/1E3,
f=document.getElementById("countdown"),g=setInterval(function(){if(0>--d)clearInterval(g);
else{for(var a=d,b=[86400,3600,60,1],c,e=-1;c=b[++e];)b[e]=("0"+parseInt(a/c,10)).slice(-2),
a%=c;f.innerHTML=b.join(":")}},1E3)})();​
added 66 characters in body
Source Link

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 3023, 2012 1822:1042:00'30');
 var secsToGo = (new Date(endDate - currentDate)).getTime() / 1000;
 var countdownElement = document.getElementById('countdown');
 
 var timer = setInterval(function() {
 
 if (! --secsToGo < 0) {
  clearInterval(timer);
 return;
 }
  countdownElement.innerHTML = secsToDHMS(secsToGo);
 
 }, 1000);
 
})();

Fiddle: http://jsfiddle.net/xg63V/2 http://jsfiddle.net/xg63V/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

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 23, 2012 22:42:30');
 var secsToGo = (new Date(endDate - currentDate)).getTime() / 1000;
 var countdownElement = document.getElementById('countdown');
 
 var timer = setInterval(function() {
 
 if (--secsToGo < 0) {
  clearInterval(timer);
 return;
 }
  countdownElement.innerHTML = secsToDHMS(secsToGo);
 
 }, 1000);
 
})();

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

Source Link

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

default

AltStyle によって変換されたページ (->オリジナル) /