<%@ page contentType="text/html;charset=utf-8"%>
<html>
<body onload="disptime();">
<FORM NAME="myform">
<DIV align="center">
<SCRIPT language="JavaScript">
<!--
function disptime( )
{
var time = new Date( ); //獲得當前時間
var year = time.getYear( );//獲得年、月、日
var month = time.getMonth( );
var day = time.getDay( );
var hour = time.getHours( ); //獲得小時、分鐘、秒
var minute = time.getMinutes( );
var second = time.getSeconds( );
var apm="AM"; //默認顯示上午: AM
if (hour>12) //按12小時制顯示
{
hour=hour-12;
apm="PM" ;
}
if (minute < 10) //如果分鐘只有1位,補0顯示
minute="0"+minute;
if (second < 10) //如果秒數(shù)只有1位,補0顯示
second="0"+second;
/*設(shè)置文本框的內(nèi)容為當前時間*/
document.myform.myclock.value =year+"年"+month+"月"+day+"日 "+hour+":"+minute+":"+second+" "+apm;
/*設(shè)置定時器每隔1秒(1000毫秒),調(diào)用函數(shù)disptime()執(zhí)行,刷新時鐘顯示*/
var myTime = setTimeout("disptime()",1000);
}
//-->
</SCRIPT>
動態(tài)顯示時間<INPUT name="myclock" type="text" value="" size="25">
<br>
靜態(tài)顯示時間 <%=new java.util.Date()%>
</body></html>