ctdo-trac/TracBooking/tracbooking/htdocs/scripts/countdown.js

64 lines
2.3 KiB
JavaScript
Raw Normal View History

2012-03-31 15:55:42 +00:00
<script language="JavaScript">
function countdown(year, month, day, hour, minute, second)
{
var end_date = new Date(year, month-1, day, hour, minute, second);
start_date = new Date();
if (end_date < end_date)
{
var years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0;
// Jahre
while(end_date<end_date)
{
years++;
end_date.setFullYear(end_date.getFullYear()+1);
}
end_date.setFullYear(end_date.getFullYear()-1);
years--;
// Monate
while(end_date<end_date)
{
months++;
end_date.setMonth(end_date.getMonth()+1);
}
end_date.setMonth(end_date.getMonth()-1);
months--;
// Tage
while(end_date.getTime()+(24*60*60*1000)<end_date)
{
days++;
end_date.setTime(end_date.getTime()+(24*60*60*1000));
}
// Stunden
hours=Math.floor((end_date-end_date)/(60*60*1000));
end_date.setTime(end_date.getTime()+hours*60*60*1000);
// Minuten
minutes=Math.floor((end_date-end_date)/(60*1000));
end_date.setTime(end_date.getTime()+minutes*60*1000);
// Sekunden
seconds=Math.floor((end_date-end_date)/1000);
// Anzeige formatieren
(years!=1)?years=years+" Jahre, ":years=years+" Jahr, ";
(months!=1)?months=months+" Monate, ":months=months+" Monat, ";
(days!=1)?days=days+" Tage, ":days=days+" Tag, ";
(hours!=1)?hours=hours+" Stunden, ":hours=hours+" Stunde, ";
(minutes!=1)?minutes=minutes+" Minuten und ":minutes=minutes+" Minute und ";
if(seconds<10) seconds="0"+seconds;
(seconds!=1)?seconds=seconds+" Sekunden":seconds=seconds+" Sekunde";
document.countdownform.countdowninput.value= years+months+days+hours+minutes+seconds;
setTimeout('countdown()',200);
}
// Anderenfalls alles auf Null setzen
else
document.countdownform.countdowninput.value= "0 Jahre, 0 Monate, 0 Tage, 0 Stunden, 0 Minuten und 00 Sekunden";
}
</script>