This is a simple function that i use on our website.
PHP Code:
function update(divID, seconds) {
obj = document.getElementById(divID);
var now = new Date();
var output = "";
var days, hours, minutes, second;
var timeUntil = seconds - Math.round(now.valueOf()/1000);
days = Math.floor(timeUntil/86400); timeUntil -= days*86400;
hours = Math.floor(timeUntil/3600); timeUntil -= hours*3600;
minutes = Math.floor(timeUntil/60); timeUntil -= minutes*60;
second = Math.floor(timeUntil);
output += days + " Days, " + hours + " Hours, " + minutes + " Minutes, " + second + " Seconds";
obj.innerHTML = output;
window.setTimeout("update('" + divID + "', " + seconds + ")", 1000);
}
You supply the ID of the tag you want to fill with the countdown, and the UNIX timestamp of the event that will be occurring. make sure that you set a preliminary timeout function before using it the first time. for example:
PHP Code:
window.setTimeout("update('feild0', 1173963600)", 0);
just for clarification, despite the tag, it is javascript.