<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>计时器</title>
</head>
<body>
<p id='dd'></p>
<button onclick="clearInterval(ll)">点我停止</button>
<script>
function myFunction() {
ll = setInterval(daojishi, 500);
}
function daojishi(){
var date = new Date()
hour = date.getHours()
if (hour<10){
hour = "0" + hour
}
document.getElementById('dd').innerText = date.getFullYear() + "/"+ date.getMonth() + "/" +
date.getDate() +" " + hour + ":" + date.getMinutes() + ":" + date.getSeconds()
// console.log(date.getFullYear())
}
myFunction();
</script>
</body>
</html>
结果展示