JS Countdown Code

Source: Internet
Author: User

First: The JavaScript countdown code that is accurate to the second



HTML code:

<formname= "Form1" >
<div align= "center" align= "Center" >
<center> there are:<br> from 2010.
<input type= "textarea" name= "left" size= "" style= "Text-align:center" >
</center>
</div>
</form>
<scriptlanguage= "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+ ' min, ' +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>






The second kind: XXX Games



HTML code:
<!--Countdown javascriptbegin-->
<scriptlanguage= "JavaScript" >
<!--
function DigitalTime1 ()
{
var deadline= new Date ("08/13/2007")//Opening Countdown
var symbol= "August 13"
var now = new Date ()
var diff = -480-now.gettimezoneoffset ()//is the time difference between Beijing and local time
var leave = (Deadline.gettime ()-now.gettime ()) + diff*60000
var day = Math.floor (Leave/(1000 * 60 * 60 *24))
var hour = Math.floor (Leave/(1000*3600))-(Day *24)
var minute = Math.floor (Leave/(1000*60))-(Day * *60)-(hour* 60)
var second = Math.floor (leave/(+))-(Day * *60*60)-(hour*)-(MINUTE*60)

var deadline_2= new Date ("08/13/2004")//timing after opening
var symbol_2= "August 13"
var now_2 = new Date ()
var diff_2 = -480-now.gettimezoneoffset ()//is the time difference between Beijing and local time
var leave_2 = (Now_2.gettime ()-Deadline_2.gettime ()) +diff_2*60000
var day_2 = Math.floor (leave_2/(1000 * 60 * 60 *24))
var hour_2 = Math.floor (leave_2/(1000*3600))-(Day_2 *24)
var minute_2 = Math.floor (leave_2/(1000*60))-(day_2 * *60)-(hour_2 * 60)
var second_2 = Math.floor (leave_2/(+))-(day_2 * *60*60)-(hour_2 *)-(MINUTE_2*60)

day=day+1;
day_2=day_2+1;

if (day>0)//Not yet opened
{
liveclock1.innerhtml = "Now" +symbol+ "Day"
liveclock1.innerhtml = "<font
SetTimeout ("DigitalTime1 ()", 1000)
}

if (day<0)//has been opened
{
liveclock1.innerhtml = "Now +symbol+" and "+day+" Day "+hour+" hours "+minute+" minutes "+second+" seconds "
liveclock1.innerhtml = "<font
SetTimeout ("DigitalTime1 ()", 1000)

}

if (day==0)//is opening
{
liveclock1.innerhtml = "Now" +symbol+ "Day"
liveclock1.innerhtml = "<font
SetTimeout ("DigitalTime1 ()", 1000)
}



if (day<0 & day_2>19)//XXX Games End
{
liveclock1.innerhtml = "Now +symbol+" and "+day+" Day "+hour+" hours "+minute+" minutes "+second+" seconds "
liveclock1.innerhtml = "<font
SetTimeout ("DigitalTime1 ()", 1000)

}

}
-
</script>
<!--Countdown javascriptend-->
<bodyonload=digitaltime1 () >
<div id=liveclock1></div>

</body>

Third type: Hour countdown



HTML code:
<scriptlanguage= "JavaScript" >
<!--
var maxtime = 60*60//One hours, calculate by seconds, adjust yourself!
function Countdown () {
if (maxtime>=0) {
Minutes =math.floor (MAXTIME/60);
Seconds =math.floor (MaxTime ');
msg = "+minutes+" and "+seconds+" seconds "at the end of the distance";
document.all["Timer"].INNERHTML=MSG;
if (MaxTime = = 5*60) alert (' Note, there are 5 minutes! ');
--maxtime;
}
else{
Clearinterval (timer);
Alert ("Time to, end!");
}
}
Timer =setinterval ("Countdown ()", 1000);
-
</SCRIPT>
<div id= "Timer" style= "color:red" ></div>






Fourth type: The simplest countdown



HTML code:
<scriptlanguage= "JavaScript" >
<!--Begin
var timedate= new Date ("january14,2006");
vartimes= "Postgraduate examination";
var now = Newdate ();
var date = Timedate.gettime ()-now.gettime ();
var time = Math.floor (Date/(1000 * 60 * 60 *24));
if (time >= 0);
document.write ("<li><fontcolor= #DEDBDE > Now from 2006" +times+ "also: <fontcolor= #ffffff ><b>" + time+ "</b></font> days </font></li>");
End-To
</Script>






The fifth kind: The simplest countdown two



HTML code:
<script language= "JavaScript" type= "Text/javascript" >
function DJs () {
var urodz= newdate ("11/12/2008");
var now = new Date ();
var num
var ile = Urodz.gettime ()-now.gettime ();
var dni = Math.floor (ile/(1000 * 60 * 60 *24));
if (dni>1)
Num=dni+1
else if (dni = = 1) num=2
else if (dni = = 0) num=1
else num=0
document.write (num)
}
</script>

From the opening ceremony there are [<script language= "JavaScript" type= "Text/javascript" >djs () </script>] Days
Fifth: JavaScript countdown timer-using system time self-calibration
The use of system time self-calibration countdown, no manual adjustment to make the countdown more accurate, code and detailed comments are as follows:

<spanid= "Clock" >00:01:11:00</span>
<input id= "STARTB" type= "button" value= "startcountdown!" Onclick= "Run ()" >
<input id= "endb" type= "button" value= "stopcountdown!" Onclick= "Stop ()" >
<br>
<input id= "diff" type= "text" >
<input id= "Next" type= "text" >
<scriptlanguage= "Javascript" >
var normalelapse = 100;
var nextelapse =normalelapse;
Varcounter;
var startTime;
var start =clock.innertext;
var finish = "00:00:00:00";
var timer = null;

Start running
function Run () {
Startb.disabled = true;
endb.disabled = false;
Counter = 0;
Initialization start time
StartTime = Newdate (). ValueOf ();

Nextelapse is timing time, initially 100 milliseconds
Note the SetInterval function: the time elapsed nextelapse (milliseconds) before OnTimer began to execute
Timer = Window.setinterval ("OnTimer ()", nextelapse);
}

Stop running
function Stop () {
startb.disabled = false;
Endb.disabled = true;
Window.cleartimeout (timer);
}

Window.onload = function () {
Endb.disabled = true;
}

Countdown function
function OnTimer ()
{

if (start = = finish)
{
Window.clearinterval (timer);
Alert ("Time is up!");
Return
}

var HMS = NewString (Start). Split (":");
var ms = Newnumber (hms[3]);
var s = newnumber (hms[2]);
var m = newnumber (hms[1]);
var h = newnumber (Hms[0]);

MS-= 10;
if (MS <0)
{
ms = 90;
S-= 1;
if (S < 0)
{
s = 59;
M-=1;
}

if (M < 0)
{
m = 59;
H-=1;
}
}

var ms = MS < 10? ("0" + ms): MS;
var ss = S < 10? ("0" + s): s;
var sm = m < 10? ("0" + m): M;
var sh = h < 10? ("0" + H): h;

Start = sh + ":" + SM + ":" + SS + ":" +MS;
Clock.innertext = start;

Clear the last Timer
Window.clearinterval (timer);

The time of the self-calibration system is time-out, and this results in the timing of the next new timer Nextelapse
counter++;
var countersecs = counter *100;
var elapsesecs = new Date (). ValueOf ()-starttime;
var diffsecs = countersecs-elapsesecs;
Nextelapse = Normalelapse +diffsecs;
Diff.value = Countersecs + "-" + elapsesecs + "=" +diffsecs;
Next.value = "Nextelapse =" +nextelapse;
if (Nextelapse < 0) Nextelapse = 0;

Start a new timer
Timer = Window.setinterval ("OnTimer ()", nextelapse);
}
</script>

JS Countdown Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.