javascript countdown
Figured I should put up my ultra-hackey code for posterity. I found lots of javascript day countdown timers, but none that did hours. I’ve put the code below. Just change the 5 variables at the beginning to what you need. Javascript counts January as the zero month so subtract one from your month (the example below is 12-6-2007 at 10:00 am):
var year = 2007;
var month = 11;
var day = 6;
var hour = 10;
var mins = 0;
var today = new Date();
var closeDate = new Date();
closeDate.setHours(hour);
closeDate.setMinutes(mins);
closeDate.setFullYear(year, month, day);
var remainingDays = Math.floor((closeDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) );
document.writeln(remainingDays);
document.writeln(” days ”);
var remainingHours = Math.ceil((closeDate.getTime() - today.getTime()) / (1000 * 60 * 60) % 24);
document.writeln(remainingHours);
hours until we close
Example:
var year = 2007; var month = 11; var day = 6; var hour = 10; var mins = 0; var today = new Date(); var closeDate = new Date(); closeDate.setHours(hour); closeDate.setMinutes(mins); closeDate.setFullYear(year, month, day); var remainingDays = Math.floor((closeDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) ); document.writeln(remainingDays); document.writeln(” days ”); var remainingHours = Math.ceil((closeDate.getTime() - today.getTime()) / (1000 * 60 * 60) % 24); document.writeln(remainingHours); hours until we close