链接描述感谢SOHO树叶的劳动成果,我稍稍添加了一点代码,感谢慕课平台。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>使用js和html动态的显示时钟</title>
</head>
<body>
<!--<input type="button" value="显示当前时间" onclick="myDate()"/>-->
<div id="div" style="width: 280px; height: 30px;"></div>
</body>
<script>
function myDate () {
var now=new Date();
var y=now.getFullYear();
var m=now.getMonth()+1;
var d=now.getDate();
var h=now.getHours();
var mi=now.getMinutes();
var s=now.getSeconds();
document.getElementById("div").innerHTML= y + '-' + (m < 10 ? ('0' + m) : m) + '-'
+ (d < 10 ? ('0' + d) : d) + " "+ (h < 10 ? ('0' + h) : h) + " : " + (mi < 10 ? ('0' + mi) : mi) + " : " + (s < 10 ? ('0' + s) : s) ;
//y + "年" + m + "月" + d + "日" + h + ":" + mi + ":" + s;
}
setInterval(myDate,1000);
</script>
</html>