<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();
var days = ["日 ", "一 ", "二 ", "三 ", "四 ", "五 ", "六 ", ] //document.getElementById("date").value = yy + "年" + MM + "月" + dd + "日 " + "星期" + days[week]; document.getElementById("time").innerHTML = yy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss; setTimeout(bodyLoad, 1000); } </script> <body onload="bodyLoad()"> <label id="time"></label> </body>