This post is describing how to create countdown timer using JQuery.If you already have a knowledge of java script time,date functions this is very easy job.OK.We’ll see how to create countdown timer using JQuery.
1-First you must load the JQuery library file.
2-This is the html content.
3-This is the countdown function.
var timezone = new Date() var gmtHours = -timezone.getTimezoneOffset()/60; month = --month; dateFuture = new Date(year,month,day,hour-gmtHours,min,sec); function countProcess(){ dateNow = new Date(); amount = dateFuture.getTime() - dateNow.getTime()+5; delete dateNow; /* time is already past */ if(amount < 0){ output ="0" + "0" + "0" + "0" ; $('#countbox').html(output); } /* date is still good */ else{ days=0; hours=0; mins=0; secs=0; output=""; amount = Math.floor(amount/1000); /* kill the milliseconds */ days = Math.floor(amount/86400); /* days */ amount = amount%86400; hours = Math.floor(amount/3600); /* hours */ amount = amount%3600; mins = Math.floor(amount/60); /* minutes */ amount = amount%60; secs = Math.floor(amount); /* seconds */ output="" + days +"" + "" + hours +"" + "" + mins +"" + "" + secs +"" ; $('#countbox').html(output); setTimeout("countProcess()", 1000); // call to the function every seconds } }
4-How to call to this function and set end date.
//pass the parameters year = 2012; month = 12; day = 25;hour= 16; min= 0; sec= 0; //call to the function start $(function(){ countProcess(); });
Put this all together.
JQuery Countdown Timer
That’s only.
View Demo
Download JQuery smart countdown timer Example (520 KB)