function zeroPad(num,count){ var numZeropad = num + ''; while(numZeropad.length < count) { numZeropad = "0" + numZeropad; } return numZeropad; } function countdown_clock(year, month, day, hour, minute, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); //Computes the time difference between the client computer and the server. Server_Date = (new Date(12, 2, 5, 20, 9, 54)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); countdown(year, month, day, hour, minute, (Todays_Date - Server_Date), format); } function countdown(year, month, day, hour, minute, time_difference, format) { Today = new Date(); Todays_Year = Today.getFullYear() - 2000; Todays_Month = Today.getMonth(); 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, 00)).getTime(); Time_Left = Math.round((Target_Date - Todays_Date + time_difference) / 1000); if(Time_Left < 0) { Time_Left = 0; document.getElementById('countdown').innerHTML = 'Afgiv din ordre idag'; document.getElementById('countdown_line1').innerHTML = ''; document.getElementById('countdown_line2').innerHTML = '... og vi sender den imorgen!'; } else { days = Math.floor(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = zeroPad(Math.floor(Time_Left / (60 * 60)),1); Time_Left %= (60 * 60); minutes = zeroPad(Math.floor(Time_Left / 60),1); Time_Left %= 60; seconds = zeroPad(Time_Left,1); document.getElementById('countdown').innerHTML = hours + ' timer '; document.getElementById('countdown').innerHTML += minutes + ' min '; document.getElementById('countdown').innerHTML += seconds + ' sek'; document.getElementById('countdown_line1').innerHTML = 'Afgiv din ordre inden...'; document.getElementById('countdown_line2').innerHTML = '... og vi sender den idag!'; setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + time_difference + ', ' + format + ');', 1000); } } countdown_clock(12, 2, 5, 0, 00, 1);