<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>显示系统时间,同时它随着系统变化而变化(格式:xxxx年x月x日 xx:xx:xx)</div>
<div id="div333"></div>
<script>
// var y=new Date();
// var m=new Date();
// var d=new Date();
// var h=new Date();
// var min=new Date();
// var s=new Date();
// document.write(y.getFullYear()+"年"+ m.getMonth()+"月"+ d.getDay()+"日 "+ h.getHours()+":")
window.onload= function () {
function mydate() {
var div33 = document.getElementById("div333");
var date = new Date();
div33.innerHTML = date.getFullYear() + ‘年‘ + (date.getMonth() + 1) + "月" + date.getDate() + ‘日‘ +
(date.getHours() < 10 ? ‘0‘ + date.getHours() : date.getHours()) + ‘:‘ +
(date.getMinutes() < 10 ? ‘0‘ + date.getMinutes() : date.getMinutes()) + ‘:‘ +
(date.getSeconds() < 10 ? ‘0‘ + date.getSeconds() : date.getSeconds());
}
setInterval(mydate,1000);
}
</script>
</body>
</html>
原文:http://www.cnblogs.com/lyh15/p/6527185.html