復制代碼 代碼如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function bodyLoad(){
var dateTime=new Date();
var hh=dateTime.getHours();//小時
var mm=dateTime.getMinutes();//分鐘
var ss=dateTime.getSeconds();//秒鐘
var yy=dateTime.getFullYear();//年份
var MM=dateTime.getMonth()+1; //月份-因為1月這個方法返回為0,所以加1
var dd=dateTime.getDate();//日數
var week=dateTime.getDay();//周(0~6,0表示星期日)
var days=[ "日 ", "一 ", "二 ", "三 ", "四 ", "五 ", "六 ",]
document.getElementById("date").innerHTML=yy+"年"+MM+"月"+dd+"日 "+"星期"+days[week] ;
document.getElementById("time").innerHTML=hh+"時"+mm+"分"+ss+"秒";
setTimeout(bodyLoad,1000);
}
</script>
</head>
<body onload="bodyLoad()">
<span id="date" ></span>
<span id="time" ></span>
</body>
</html>