前言:获取当前时间(正常人能看懂的时间)
效果:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<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
}
console.log(formatDate());//当前时间
</script>
</body>
</html>