JavaScript implementation Countdown

Source: Internet
Author: User
Tags local time

This article to share is the personal project used in the JavaScript implementation of the accurate to the second level countdown code, very practical, the need for small partners can refer to.

The code is quite simple and practical, here is no more nonsense, the small friends can see the simple

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> </head> <body> <div id=" demo01 "class=" Colockbox "> Remaining <i class=" Day ">0< /i> Day <i class= "Hour" >0</i> <i class= "minute" >0</i> <i class= "Second" >0</i> sec <input id= "End_time_gou" type= "hidden" value= "2015/08/20 13:00:00" > <input id= "Now_gou" type= "hidden" value= " 2015/06/25 11:44:08 "> </div>   <div id=" timer "class=" Colockbox "> </div> <script type=" Text/javascript "src=" http://code.jquery.com/jquery-1.9.0.min.js "></script> <script> var time_end = $ (' #end_time_gou '). Val (); var time_now_server = $ (' #now_gou '). Val (); Countdown (Time_end,time_now_server, "#demo01. Day", "#demo01. Hour", "#demo01. Minute", "#demo01. Second"); function Countdown (Endtime,now,day_elem,hour_elem,minute_elem,second_elem) {var end_time = new Date (endtime). GetTime (),//month is the actual month-1 current_time = new Date (now). GetTime (), Sys_second = (end_time-current_time)/1000; var timer = setinterval (function () {if (Sys_second > 0) {sys_second-= 1; var day = Math.floor ((sys_second/3600)/2 4); var hour = Math.floor ((sys_second/3600)% 24); var minute = Math.floor ((SYS_SECOND/60)% 60); var second = Math.floor (sys_second% 60); Day_elem && $ (day_elem). Text (day);//Calculate Days $ (Hour_elem). Text (hour<10? ") 0 "+hour:hour);//Compute Hour $ (minute_elem). Text (minute<10?) 0 "+minute:minute);//Compute cents (Second_elem). Text (second<10?) 0 "+second:second);//calculation seconds} else {clearinterval (timer);}}, 1000); } </script> <script type= "Text/javascript" > var time_now_server,time_now_client,time_end,time_server_ Client,timerid; Time_end=new Date ($ (' #end_time_gou '). Val ());//End Time Time_end=time_end.gettime (); Time_now_server=new Date ($ (' #now_gou '). Val ());/start time, Server time_now_server= time_now_server.gettime (); Time_now_client=new Date (); Time_now_client=time_now_client.gettime ()//local time time_server_client=time_now_server-time_now_client; settimeout ("Show_time" ("+time_end+", "+time_server_client+", "+timerid+") ", 1000); function Show_time (time_end,time_server_client,timerid) {var timer = document.getElementById (' timer '); if (!timer) { return;} timer.innerhtml = timer.innerhtml; var time_now,time_distance,str_time; var Int_day,int_hour,int_minute,int_second; var time_now=new Date (); Time_now=time_now.gettime () +time_server_client; Time_distance=time_end-time_now; if (time_distance>0) {Int_day=math.floor (time_distance/86400000) time_distance-=int_day*86400000; int_hour= Math.floor (time_distance/3600000) time_distance-=int_hour*3600000; Int_minute=math.floor (time_distance/60000) time_distance-=int_minute*60000; Int_second=math.floor (time_distance/1000) if (int_hour<10) int_hour= "0" +int_hour; if (int_minute<10) int_minute= "0" +int_minute; if (Int_SECOND<10) int_second= "0" +int_second; str_time=int_day+ "Days" +int_hour+ "hours" +int_minute+ "minutes" +int_second+ "seconds"; Timer.innerhtml=str_time; settimeout ("Show_time" ("+time_end+", "+time_server_client+", "+timerid+") ", 1000); }else{timer.innerhtml =timer.innerhtml cleartimeout (Timerid)}}   </script> </body> </html>

The above is the entire contents of this article, I hope you can enjoy.

Related Article

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.