静态时间:
1.页面首部添加 <%@page import="java.util.Date"%>
2.页面body中需要显示时间的地方使用 <%= new Date().toString() %> 即可。
-------另:页面添加刷新按钮------
<input type="button" οnclick="javascript:window.location.reload()" value="刷新"/>
另一种简单粗暴的方法:
在需要显示时间的地方写上 <%=(new java.util.Date()).toLocaleString()%> 就可以了。
动态时间:
使用javascript。
<script language=JavaScript>
var timerID = null;
var timerRunning = false;
function stopclock() {
if (timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock() {
stopclock();
showtime();
}
function showtime() {
var now = new Date();
document.clock.thetime.value = now.toString();
timerID = setTimeout("showtime()", 1000);
timerRunning = true;
}
</script>
在body中使用下面的代码显示时间。
<body οnlοad="startclock()">
<form name=clock >
<input name=thetime style="font-size: 9pt;color:#000000;border:0" size=100>
</form>
</body>
注:其中javascript代码中startclock()和stopclock()两个函数可以不要,在onload处改成
οnlοad="showtime()"
就可以了。