前言:实时显示当前时间(中文版),一周的第几天用中文显示
效果:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div id="box"></div>
<script src='jquery.min.js'></script>
<script>
function formatDate() {
now = new Date();
var year = now.getFullYear(),
month = now.getMonth() + 1,
date = now.getDate(),
day = now.getDay(),
hour = now.getHours(),
minute = now.getMinutes(),
second = now.getSeconds();
minute = checkTime(minute);
month = checkTime(month);
date = checkTime(date);
hour = checkTime(hour);
second = checkTime(second);
return year + " / " + month + " / " + date + " 星期"+ day +" " + hour + ":" + minute + ":" + second;
}
function checkTime(i) {
if(i < 10) {
i = "0" + i
}
return i
}
showtime();
function showtime(){
var gettime = formatDate();
$("#box").text(gettime);
}
setInterval(function(){
showtime();//封装的显示时间的方法
},1000);
</script>
</body>
</html>