// taken from http://scripts.franciscocharrua.com/countdown-clock.php // modified specifically for Peter's Date Countdown: http://www.theblog.ca/?p=41 function countdown_clock(year, month, day, hour, minute, i, timediff) { html_code = ''; document.write(html_code); countdown(year, month, day, hour, minute, i, timediff); } function countdown(year, month, day, hour, minute, i, timediff) { Today = new Date(); pdc_servergmt = -5; pdc_gmt = pdc_servergmt + Today.getTimezoneOffset()/60; Todays_Hour = Today.getHours() + pdc_gmt + timediff; //Convert both today's date and the target date into milliseconds. Todays_Date = (new Date(Today.getFullYear(), Today.getMonth(), Today.getDate(), Todays_Hour, Today.getMinutes(), Today.getSeconds())).getTime(); Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime(); // Find their difference, and convert that into seconds. Time_Left = Math.round((Target_Date - Todays_Date) / 1000); if(Time_Left > 0) { 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; } else if(Time_Left < 0) { days = Math.ceil(Time_Left / (60 * 60 * 24)); Time_Left %= (60 * 60 * 24); hours = Math.ceil(Time_Left / (60 * 60)); Time_Left %= (60 * 60); minutes = Math.ceil(Time_Left / 60); Time_Left %= 60; seconds = Time_Left; } dps = 's'; //ps is short for plural suffix. if(Math.abs(days) == 1) dps =''; pdc_div = document.getElementById('pdc_item' + i); pdc_div.innerHTML = '' + days + ' day' + dps + ' '; pdc_div.innerHTML += hours + 'h' + ' '; pdc_div.innerHTML += minutes + 'm' + ' '; pdc_div.innerHTML += seconds + 's' + ' '; // Recursive call, keeps the clock ticking. setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + i + "," + timediff + ');', 1000); }