Project structure:
Operation Effect:
=========================================================
Code section:
=========================================================
/clock/webcontent/index.jsp
Copy Code code as follows:
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://"
+ request.getservername () + ":" + request.getserverport ()
+ path + "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<base href= "<%=basePath%>"/>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<span id= "Clock" > </span>
</body>
<script type= "Text/javascript" src= "<%=basepath%>js/clock/clock.js" charset= "UTF-8" ></script>
/clock/webcontent/js/clock/clock.js
Copy Code code as follows:
/**
* Time Display
* @date 2012-12-31
* @author Hongten (hongtenzone@foxmail.com)
*
* @returns
*/
function Clock () {
var date = new Date ();
This.year = Date.getfullyear ();
This.month = Date.getmonth () + 1;
This.date = Date.getdate ();
This.day = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") [Date.getday ()];
This.hour = Date.gethours () < 10? "0" + date.gethours (): Date.gethours ();
This.minute = Date.getminutes () < 10? "0" + date.getminutes (): Date.getminutes ();
This.second = Date.getseconds () < 10? "0" + date.getseconds (): Date.getseconds ();
Date: 2012-12-31-17:03:18 Monday
this.tostring = function () {
Return "Date:" + This.year + "-" + This.month + "-" + this.date + "-" + This.hour + ":" + This.minute + ":" + This.second + "" + this.day;
};
2012-12-31
This.tosimpledate = function () {
return this.year + "-" + This.month + "-" + this.date;
};
2012-12-31 17:04:03
This.todetaildate = function () {
return this.year + "-" + This.month + "-" + This.date + "" + This.hour + ":" + This.minute + ":" + this.second;
};
This.display = function (ele) {
var clock = new Clock ();
ele.innerhtml = Clock.tostring ();
Window.settimeout (function () {
Clock.display (ele);
}, 1000);
};
}
<span id= "Clock" > </span>
var clock = new Clock ();
Clock.display (document.getElementById ("clock"));
I personally think this is very useful in the web ... So recommended to everyone ...