JS Countdown Timer

Source: Internet
Author: User
Tags setinterval
1.JS Countdown TimerHTML code:
<p>
   <span id= "test" style= "Display:block font-size:20px; font-weight:700; color: #0F0;" > Distance party start time:</span>
</p>
JS Code:
var timer; var maxtime = 3600;  
One hours, in seconds, adjust yourself! 
			function Countdown () {if (maxtime>=0) {time = Formatminutes (maxtime);   
			document.getElementById ("Test"). Innerhtml=time;   
			if (MaxTime!=0) {--maxtime;   
			}else{clearinterval (timer);
    }} function Formatminutes (minutes) {var day = parseint (Math.floor (minutes/86400)); var hour = Day >0? 
    Math.floor ((minutes-day*86400)/3600): Math.floor (minutes/3600); var minute = hour > 0?
    Math.floor ((minutes-day*86400-hour*3600)/60): Math.floor (MINUTES/60); var second = minute > 0?
    Math.floor (minutes-day*86400-hour*3600-minute*60): minutes;      
    var time= "";
    if (Day > 0) Time + + + "days";
    if (Hour > 0) Time + = Hour + "Hour";
    if (Minute > 0) Time + = minute + "minutes";
    Time + = second+ "seconds";
    Time = "distance from the end of the party also:" +time;
return time;
	 function Dateformate (currenttimemillis) {var d = new Date ();
	D.settime (Currenttimemillis); var str = D.format ("YYYY year mm month DD HH:mm:ss ");
	var str = D.format ("YYYY year mm month DD Day Hh:mm:ss");
document.getElementById ("Test1"). Innerhtml= "Converted time:" +STR;}
	$ (document). Ready (function () {//dateformate (' 1392818810270 ');	
Timer = SetInterval ("Countdown ()", 1000); });
In the code above, call the setinterval timer, call the countdown () function every 1000 milliseconds, and the countdown implementation is reduced by one second every second to achieve
To the number timer, the global variable maxtime the time point of the countdown, which needs to be converted to a number of seconds.
The foreground effect is:
Ps:
var begindate=new date ()//start date
var enddate=new date (' 2014 ', ' 1 ', ' 25 ', ' 16 ', ' 10 ', ' 30 ');/end Date
var maxtime = Math.Round ((Enddate.gettime ()-begindate.gettime ())/1000);
The above two lines of code, you can get two points between the number of seconds, for the countdown

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.