CV用;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
text-align: center;
margin-top:80px;
}
</style>
</head>
<body>
<div id="d1"></div>
<script>
var date=new Date(); //全局用 当前时间
function dateFormat(date) { //时间格式 年月日时分秒 +星期
var y=date.getFullYear(),
month=date.getMonth() + 1,
m=month<10 ? "0"+month : month,
d=(date.getDate()<10) ? "0"+date.getDate() : date.getDate(),
h=(date.getHours()<10) ? "0"+date.getHours() : date.getHours(),
mi=(date.getMinutes()<10) ? "0"+date.getMinutes() : date.getMinutes(),
s=(date.getSeconds()<10) ? "0"+date.getSeconds() : date.getSeconds(),
day=weekSwitch(date.getDay());
var sendDate=y + "-" +m + "-" +d + " " +h + ":" +mi + ":"+s +" " +day;
console.log(sendDate);
return sendDate;
}
function weekSwitch(n){
switch (n) {
case 1:
return "星期一";
case 2:
return "星期二";
case 3:
return "星期三";
case 4:
return "星期四";
case 5:
return "星期五";
case 6:
return "星期六";
case 0:
return "星期日";
}
}
document.getElementById("d1").innerHTML=dateFormat(date);
setInterval(function () {
document.getElementById("d1").innerHTML=dateFormat(new Date());
},1000)
</script>
</body>
</html>
效果图: