Countdown module (Gets the time on the server-the snapping module for the shopping site)

Source: Internet
Author: User
Tags diff

JS section

/*Ajax Request Server Current time*/functionServertiems () {varA=NULL; Try{A=NewActiveXObject ("Msxml2.xmlhttp")   } Catch(e) {Try{A=NewActiveXObject ("Microsoft.XMLHTTP")     } Catch(OC) {A=NULL    }  }  if( ! A &&typeofXMLHttpRequest! = "undefined") {A=NewXMLHttpRequest ()}returnA}varNowtime; varTM =Servertiems (); varStrdata= "auto=" +NewDate (). toString (); Tm.onreadystatechange=Callback_st; Tm.open ("GET", "HTTP//Your server output address",false);//server output format such as: {"Time": "2016/4/29 11:24:11"}Tm.setrequestheader ("Content-type", "application/x-www-form-urlencoded");   Tm.send (strdata); functionCallback_st () {if(Tm.readystate==4 && tm.status==200){    varresult =Tm.responsetext; varJSON = eval ("(" + result + ")"); Nowtime=json.time;//gets the current time to the server        }}vartoday=NewDate (nowtime). GetTime ();varnow =NewDate (). GetTime ();vardiff = (now-today);functionShow_date_timezj (TIMESXX,XID) {window.settimeout (function() {SHOW_DATE_TIMEZJ (TIMESXX,XID)},20); BirthDay=NewDate (TIMESXX);//Set DatevarNow_fun =NewDate (). GetTime ();varTodayx=now_fun-Diff;timeold= (Birthday-now_fun +diff); Sectimeold=timeold/1000;secondsold=Math.floor (sectimeold); Msperday=86400000; //* DaysE_daysold=timeold/msperday;daysold=Math.floor (e_daysold);//* HoursE_hrsold= (E_daysold-daysold) *24; Hrsold=Math.floor (e_hrsold); E_minsold= (e_hrsold-hrsold) *60; Minsold=math.floor ((e_hrsold-hrsold) *60); E_seconds= (e_minsold-minsold) *60; seconds=math.floor ((e_minsold-minsold) *60); Ms= e_seconds-Seconds;ms=NewString (ms) Ms= Ms.substr (2,3);if(daysold>=0) {document.getElementById (XID). InnerHTML= "<span> distance start time: <font color= ' #ff0000 ' >" + (daysold<10? ') 0 ' +daysold:daysold) + "</font> days </span>" + "<span><font color= ' #ff0000 ' >" + (hrsold<10? ') 0 ' +hrsold:hrsold) + "</font> hours </span>" + "<span><font color= ' #ff0000 ' >" + (minsold<10? ') 0 ' +minsold:minsold) + "</font> </span>" + "<span><font color= ' #ff0000 ' >" + (seconds<10? ') 0 ' +seconds:seconds) + "</font> sec </span>" + "<span><font color= ' #ff0000 ' >" +ms+ "</font> <span> ";}Else{document.getElementById (XID). InnerHTML= ' ';d Ocument.getelementbyid (XID). Nextsibling.classname= ' ';}}

HTML section

<Div><DivID= "Span_k1"></Div><ahref=""class= "No_ac">Enter</a><DivID= "Span_k2"></Div><ahref=""class= "No_ac">Enter</a><DivID= "Span_k3"></Div><ahref=""class= "No_ac">Enter</a></Div>

JS Call

var spank1=New show_date_timezj ("05/06/2015 19:30:00", "Span_k1"); var spank2=New show_date_timezj ("05/07/2015 09:00:00", "Span_k2"); var spank3=New show_date_timezj ("05/08/2015 19:00:00", "Span_k3");

Countdown module (Gets the time on the server-the snapping module for the shopping site)

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.