Cases
Accurate to the day of the countdown
code is as follows |
copy code |
<script Language= "JavaScript" <!--//(c) Henryk Gajewski var urodz= new Date ("09/19/2013"); var s= "Mid-Autumn Festival" ; var now = new Date (); var ile = Urodz.gettime ()-now.gettime (); var dni = Math.floor (ile/(1000 * 60 * 60 * 24)); if (Dni > 1) document.write ("+s+" and "+dni + day") else if (dni = 1) &nbs P document.write ("Only 2 days!") Else if (dni = 0) document.write ("Only 1 days!") Else document.write ("seems to have passed!"). "); //; |
JavaScript countdown code for accurate to second
HTML code:
The code is as follows |
Copy Code |
<form name= "Form1" > <div align= "center" align= "Center" > <center> there's:<br> from 2010. <input type= "textarea" name= "left" size= "style=" > </center> </div> </form> <script language= "JavaScript" > Startclock () var timerid = null; var timerrunning = false; function Showtime () { Today = new Date (); var nowhour = today.gethours (); var nowminute = Today.getminutes (); var nowmonth = Today.getmonth (); var nowdate = Today.getdate (); var nowyear = Today.getyear (); var nowsecond = Today.getseconds (); if (Nowyear <2000) Nowyear=1900+nowyear; today = NULL; Hourleft = 23-nowhour Minuteleft = 59-nowminute Secondleft = 59-nowsecond Yearleft = 2009-nowyear Monthleft = 12-nowmonth-1 Dateleft = 31-nowdate if (secondleft<0) { Secondleft=60+secondleft; minuteleft=minuteleft-1; } if (minuteleft<0) { Minuteleft=60+minuteleft; hourleft=hourleft-1; } if (hourleft<0) { Hourleft=24+hourleft; dateleft=dateleft-1; } if (dateleft<0) { Dateleft=31+dateleft; monthleft=monthleft-1; } if (monthleft<0) { Monthleft=12+monthleft; yearleft=yearleft-1; } temp=yearleft+ ' year, ' +monthleft+ ' month, ' +dateleft+ ' Day, ' +hourleft+ ' hour, ' +minuteleft+ ' minutes, ' +secondleft+ ' seconds ' Document.form1.left.value=temp; Timerid = settimeout ("Showtime ()", 1000); Timerrunning = true; } var timerid = null; var timerrunning = false; function Stopclock () { if (timerrunning) Cleartimeout (Timerid); Timerrunning = false; } function Startclock () { Stopclock (); Showtime (); } --> </script> |