<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 250px;
height: 250px;
margin: 250px auto;
border: 1px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div></div>
<script>
function time(){
var date = new Date();
var year = date.getFullYear();//年
var month = date.getMonth()+1;//月;因为month属性从0开始所以要加1
month = month<10?"0"+month:month;
var day = date.getDate();//天
day = day<10?"0"+day:day;
var week = date.getDay();//周
var arr = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
var hour = date.getHours();//小时
hour = hour<10?"0"+hour:hour;
var minute = date.getMinutes();//分钟
minute = minute<10?"0"+minute:minute;
var second = date.getSeconds();//秒
second = second<10?"0"+second:second;
var currentTime = year+"-"+month+"-"+day+" "+arr[week]+" "+hour+":"+minute+":"+second;
document.querySelector("div").innerHTML=currentTime;
}
setInterval("time()",1000);//每隔1000毫秒(1秒=1000毫秒)显示一次当前时间
clearInterval("time()")
</script>
</body>
</html>