Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<% @ Include file = "/commons/meta. jsp" %>
<% @ Include file = "/commons/meta-et.jsp" %>
<%
Calendar cal = Calendar. getInstance ();
Int hour = cal. get (cal. HOUR_OF_DAY );
Int minute = cal. get (cal. MINUTE );
Int month = cal. get (cal. MONTH );
Int date = cal. get (cal. DATE );
Int year = cal. get (cal. YEAR );
Int second = cal. get (cal. SECOND );
%>
<Script type = "text/javascript" defer = "defer">
Var NowHour = ""; // Today. getHours ();
Var NowMinute = ""; // Today. getMinutes ();
Var NowMonth = ""; // Today. getMonth ();
Var NowDate = ""; // Today. getDate ();
Var NowYear = ""; // Today. getYear ();
Var NowSecond = ""; // Today. getSeconds ();
// Obtain the server time
Function getTime (){
NowHour = <% = hour %>;
NowMinute = <% = minute %>;
NowMonth = <% = month %>;
// NowMonth = (parseInt (NowMonth) + 1 );
NowDate = <% = date %>;
NowYear = <% = year %>;
NowSecond = <% = second %>;
}
GetTime ();
Startclock ();
Var timerID = null;
Var timerRunning = false;
Function showtime (){
Var time = '$ {enddate}'; // obtain the end time or start time of the database, and then start to calculate the difference between the start time and the end time.
NowSecond = (parseInt (NowSecond) + 1 );
//-------------------------------------------------------------------
Var a, a1, a2;
Var EndTime;
A = unescape ('$ {enddate }'). split (""); // This is a comment. This sentence is the key to countdown accuracy and can be adjusted to other time needed, for example, 2012-12-20.
If (a. length> 1 ){
A1 = a [0]. split ("-");
A2 = a [1]. split (":");
EndTime = new Date (a1 [0], a1 [1]-1, a1 [2], a2 [0], a2 [1], a2 [2]);
}
Var NowTime = new Date (NowYear, NowMonth, NowDate, NowHour, NowMinute, NowSecond );
Var nMS = EndTime. getTime ()-NowTime. getTime ();
Var nD = Math. floor (nMS/(1000*60*60*24 ));
Var nH = Math. floor (nMS/(1000*60*60) % 24;
Var nM = Math. floor (nMS/(1000*60) % 60;
Var nS = Math. floor (nMS/1000) % 60;
Var dddd = nD + '-' + nH + '-' + nM + '-' + nS;
If (nD> = 0 ){
Document. getElementById ('remaind'). innerText = nD;
Document. getElementById ('remainh'). innerText = nH;
Document. getElementById ('remainm'). innerText = nM;
Document. getElementById ('remains'). innerText = nS;
} Else {
Document. getElementById ('countmsg'). innerText = "all time! ";
}
SetTimeout ("showtime ()", 1000 );
}
Function startclock (){
Showtime (); // call the time difference calculation method and display
}
</Script>
</Head>
<Body>
<Div id = "CountMsg">
<Font color = "red" size = 5> <strong id = "RemainD"> XX </strong> days <strong id = "RemainH"> XX </ <strong id = "RemainM"> XX </strong> <strong id = "RemainS"> XX </strong> seconds </font>
</Div>
</Body>
</Html>