Hallo zusammen,
Mein kleines CountDown- Sript hat bis dato (letztes Jahr) eigentlich immer funktioniert, doch habe ich heute festgestellt, das der Counter um plötzlich um einen Tag zu Früh endet.
Ich kann den Fehler auch nach längerer Suche leider nicht finden, hab ich eventuell Scheuklappen auf?
Kann das auch was mit dem Schaltjahr zu tun haben?
Hoffe jemand kann mir helfen, hier der Code:
[code lang=javascript
function countdown_clock(year, month, day, hour, minute, second, format, timestamp) {
difference = parseInt(new Date().getTime()) - parseInt(timestamp);
html_code = '<span id="countdown">counter</span>'; //Container für die Ausgabe
document.write(html_code);
countdown(year, month, day, hour, minute, second, format, difference);
}
function countdown(year, month, day, hour, minute, second, format, difference) {
if(year > 2000) year = year - 2000;
Today = new Date();
Today.setTime(Today.getTime() - difference);
Todays_Year = Today.getFullYear() - 2000;
Todays_Month = Today.getMonth() + 1;
Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
Target_Date = (new Date(year, month, day, hour, minute, second)).getTime();
Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
if(Time_Left < 0) format = '';
switch(format) {
case 0:
//Zeigt Tage, Stunden, Minuten und Sekunden
days = Math.floor(Time_Left / (60 * 60 * 24));
Time_Left %= (60 * 60 * 24);
hours = Math.floor(Time_Left / (60 * 60));
Time_Left %= (60 * 60);
minutes = Math.floor(Time_Left / 60);
Time_Left %= 60;
seconds = Time_Left;
dps = ' Tage'; hps = ' Std.'; mps = ' min'; sps = ' s';
if(days == 1) dps =' Tag';
if(hours == 1) hps =' Std.';
if(minutes == 1) mps =' min';
if(seconds == 1) sps =' s';
document.getElementById('countdown').innerHTML = 'noch:' + '<br>';
document.getElementById('countdown').innerHTML += days + dps + ' ';
document.getElementById('countdown').innerHTML += hours + hps + '<br>';
document.getElementById('countdown').innerHTML += minutes + mps + ' & ';
document.getElementById('countdown').innerHTML += seconds + sps;
break;
case 1:
//Dynamisch, blendet null Werte aus
dyn = Time_Left;
days = Math.floor(Time_Left / (60 * 60 * 24));
Time_Left %= (60 * 60 * 24);
hours = Math.floor(Time_Left / (60 * 60));
Time_Left %= (60 * 60);
minutes = Math.floor(Time_Left / 60);
Time_Left %= 60;
seconds = Time_Left;
dps = ' Tage'; hps = ' Std.'; mps = ' min'; sps = ' s';
if(days == 1) dps =' Tag';
if(hours == 1) hps =' Std.';
if(minutes == 1) mps =' min';
if(seconds == 1) sps =' s';
document.getElementById('countdown').innerHTML = 'noch:' + '<br>';
if(days > 0) document.getElementById('countdown').innerHTML += days + dps + ' ';
if(hours > 0) document.getElementById('countdown').innerHTML += hours + hps + '<br>';
if(minutes > 0) document.getElementById('countdown').innerHTML += minutes + mps + ' & ';
if(seconds > 0) document.getElementById('countdown').innerHTML += seconds + sps;
break;
case 2:
//Dynamisch, zeigt immer nur die größt mögliche Einheit
dyn = Time_Left;
days = Math.floor(Time_Left / (60 * 60 * 24));
Time_Left %= (60 * 60 * 24);
hours = Math.floor(Time_Left / (60 * 60));
Time_Left %= (60 * 60);
minutes = Math.floor(Time_Left / 60);
Time_Left %= 60;
seconds = Time_Left;
dps = ' Tage'; hps = ' Stdunden'; mps = ' Minuten'; sps = ' Sekunden';
if(days == 1) dps =' Tag';
if(hours == 1) hps =' Stdunde';
if(minutes == 1) mps =' Minute';
if(seconds == 1) sps =' Sekunde';
document.getElementById('countdown').innerHTML = 'noch:' + '<br>';
if(dyn > 86400) document.getElementById('countdown').innerHTML += days + dps;
if(dyn < 86400 && dyn > 3600) document.getElementById('countdown').innerHTML += hours + hps;
if(dyn < 3600 && dyn > 60) document.getElementById('countdown').innerHTML += minutes + mps;
if(dyn < 60) document.getElementById('countdown').innerHTML += seconds + sps;
break;
default:
//Zeigt Ausgabe wenn die Zeit erreicht ist
document.getElementById('countdown').innerHTML = '3...2..1.';
}
setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + format + ',' + difference + ');', 1000);
}
[/code]