JSP get server time in the form of Countdown to the page display _jsp programming

Source: Internet
Author: User
Copy Code code as follows:

<%@ page language= "java" import= "java.util.*"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<%@ 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 ();
Get service-side 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} '//Get the end or start time in the database, and then start calculating how long it is before the start or end
Nowsecond = (parseint (nowsecond) +1);
//-------------------------------------------------------------------
var A, a1, A2;
var Endtime;
A = Unescape (' ${enddate} '). Split (""); This is a note, this sentence is the key to the accuracy of the countdown, adjusted to other required time, such as 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 the time!" ";
}
SetTimeout ("Showtime ()", 1000);
}
function Startclock () {
Showtime (); Call the calculation time difference method and display
}
</script>
<body>
<div id= "Countmsg" >
The distance ends with <font color= "Red" Size=5><strong id= "Remaind" >XX</strong> day <strong id= "Remainh" >xx </strong> <strong id= "remainm" >XX</strong> <strong id= "remains" >XX</strong> sec </ Font>
</div>
</body>
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.