//new Date(year, month, day, hours, minutes, seconds, milliseconds) //var eventDate= new Date(2011,8,3,7,0,0,0); var eventDate= new Date("August 15, 2012 19:00:00"); var viewersTimezoneOffset= ""; var daysLeft= "174"; var hoursLeft= "4"; var minutesLeft= "58"; var secondsLeft= "43"; $(document).ready(function() { //calculateTimezoneOffset(); performCountdown(); }); function calculateTimezoneOffset() { var timezoneDate= new Date(); //The getTimezoneOffset function returns the number of minutes west of GMT the user's/viewer's browser is. For example, a browser in the New York EST timezone would be 300 minutes off of GMT. NOTE: does not factor in Daylight Savings Time. viewersTimezoneOffset= (timezoneDate.getTimezoneOffset()*60)*1000; } //end of calculateTimezoneOffset function performCountdown() { //calculateRemainingTime(eventDate); displayRemainingTime(); //This will cause the process to repeat every second (1000 milliseconds) window.setTimeout("performCountdown()","1000"); } //end of performCountdown function function calculateRemainingTime(eventDate) { var todaysDate= new Date(); //Factor in the time zone of the viewer's' browser before determining the time between now and the event start time. var timeDifference= (eventDate-viewersTimezoneOffset)-todaysDate; if (timeDifference > 0) { //Perform the calculations daysLeft= Math.floor((((timeDifference/1000)/60)/60)/24); hoursLeft= Math.floor((((timeDifference/1000)/60)/60) % 24); minutesLeft= Math.floor(((timeDifference/1000)/60) % 60); secondsLeft= Math.floor((timeDifference/1000) % 60); } else { //The event has started or is in the past, so replace the countdown with a message //$("#countdown").html("

The Dublin Horse Show<\/strong><\/h1>
"); $("#countdown").addClass("hide4print"); } } //end of calculateRemainingTime function function displayRemainingTime() { if (daysLeft > 0) { if (daysLeft < 2) { $("#dayLabel").text("Day"); } $("#daysCounter").text(daysLeft); } else { $("#daysCounter").text("0"); $("#daysCounter").parents("ul").parents("div").addClass("hideElement"); } $("#hoursCounter").text(hoursLeft); $("#minutesCounter").text(minutesLeft); $("#secondsCounter").text(secondsLeft); } //end of displayRemainingTime function