js在页面显示日期时间
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h3></h3>
<script>
function tt() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var second = date.getSeconds();
var ms = date.getMilliseconds();
var w = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
var week = date.getDay();
// console.log(w[week]);
var hh = document.querySelector("h3");
hh.innerHTML = "当前时间是:" + year + "年" + month + "月" + day + "日" + w[week] + " " + bl(hour) + ":" + bl(min) + ":" + bl(second);
}
function bl(x) {
return x >= 10 ? x : '0' + x;
}
tt();
setInterval(tt,1000)
</script>
</body>
</html>
会动的。