Simply using JS, new date (), the client time is displayed in real time on the page.
<Div id = "showdatetime"> <SCRIPT type = "text/JavaScript"
Language = "JavaScript">
Setinterval ("showdatetime. innerhtml = 'current time: '+ new date (). tolocalestring ();", 1000 );
</SCRIPT> </div>
Java + JS is required. The Code is as follows:
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<% @ Page import = "Java. util. *" %>
<% @ Taglib prefix = "F" uri = "http://java.sun.com/jsf/core" %>
<% @ Taglib prefix = "H" uri = "http://java.sun.com/jsf/html" %>
<% @ Taglib uri = "http://myfaces.apache.org/extensions" prefix = "X" %>
<% @ Taglib uri = "http://www.ccb.cn/xmdc" prefix = "xmdc" %>
<% @ Taglib prefix = "ig"
Uri = "http://www.infragistics.com/faces/netadvantage" %>
<%
Calendar CLD = calendar. getinstance ();
ClD. settime (new date ());
Int Nian = ClD. Get (calendar. year );
Int Yue = ClD. Get (calendar. month );
Int rI = ClD. Get (calendar. date );
Int Si = ClD. Get (calendar. hour_of_day );
Int Fen = ClD. Get (calendar. Minute );
Int Miao = ClD. Get (calendar. Second );
%>
<Xmdc: panelgrid columns = "2" width = "100%" columnclasses = "Left, right"
Styleclass = "top_bg">
<Xmdc: graphicimage url = "/supres/images/logo/logo1.gif" Height = "51"/>
<Xmdc: panelgrid styleclass = "state">
<X: panelgroup>
<Xmdc: outputtext value = "institution: # {sessionbean. userinfo. orgname }"
Title = "# {sessionbean. userinfo. orgid}"/>
<Xmdc: outputtext value = "| User: # {sessionbean. userinfo. name}"/>
<F: verbatim>
<Div id = "showdatetime"> <script language = JavaScript>
<! --
// Gjg add
// Use the Java date to retrieve the server time, and then use js to refresh every second. The number of seconds + 1
Var y = "<% = Nian %> ";
VaR M = "<% = Yue %> ";
VaR d = "<% = Ri %> ";
VaR H = "<% = Si %> ";
VaR F = "<% = Fen %> ";
VaR S = "<% = Miao %> ";
// This sentence is very important
// Convert to the JS Date Format
// Enter the current server time here
VaR now = new date (Y, M, D, H, F, S );
Function curenttime (){
VaR Mm = now. getminutes ();
VaR Ss = now. gettime () % 60000; SS = (SS-(SS % 1000)/1000;
VaR clock = now. gethours () + ':';
If (mm <10) Clock + = '0 ';
Clock + = mm + ':';
If (SS <10) Clock + = '0 ';
Return (clock + SS );
}
Function refresh (){
Document. getelementbyid ("showdatetime "). innerhtml = now. getyear () + "year" + (now. getmonth () + 1) + "month" + now. getdate () + "day" + curenttime (); now. setseconds (now. getseconds () + 1 );}
Setinterval ('refresh () ', 1000 );
// -->
</SCRIPT> </div>
</F: verbatim>
<Xmdc: outputlink value = "/LAA/logout. JSF">
<Xmdc: outputtext value = "[exit system]"/>
</Xmdc: outputlink>
</X: panelgroup>
</Xmdc: panelgrid>
</Xmdc: panelgrid>
<Xmdc: panelgrid width = "100%" border = "0" cellspacing = "0" cellpadding = "0"
Columns = "2" styleclass = "menu">
<Xmdc: panelgrid columns = "3" border = "0" cellspacing = "0" cellpadding = "0"
Style = "float: Left">
<Ig: menu id = "menu" binding = "# {usermenu}"> </Ig: menu>
</Xmdc: panelgrid>
</Xmdc: panelgrid>
Another JSP that can run directly on the server:
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. *, java. Text. *" %>
<% @ Page Language = "Java" %>
<HTML>
<Head>
<% Java. Text. simpledateformat formatter = new java. Text. simpledateformat (
"H: M: s ");
String servertime = formatter. Format (new date ());
%>
<Script language = "JavaScript">
VaR T = "<% = servertime %> ";
VaR TT = T. Split (":");
VaR hour = parseint (TT [0]);
VaR minute = parseint (TT [1]);
VaR second = parseint (TT [2]);
Function writetime (){
Second ++;
If (second> 59 ){
Second = 0;
Minute ++;
}
If (minute> 59 ){
Minute = 0;
Hour ++;
}
If (hour> 23) {hour = 0 ;}
VaR S = (hour <10? "0": "") + hour + ":" + (minute <10? "0": "") + minute + ":" + (second <10? "0": "") + second;
Document. All ("spantime"). innerhtml = s;
}
T = setinterval ("writetime ()", 1000 );
</SCRIPT>
</Head>
<Body topmargin = "0" leftmargin = "2" rightmargin = "0" bottommargin = "0">
Current Time:
<B> <span id = "spantime"> </span> </B>
</Body>
</Html>