<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="disp">
</div>
<input type="button" value="获取当前时间" οnclick="getNowTime()">
<script>
function getNowTime(){
var disp = document.getElementById("disp");
var nowTime = new Date();
var year = nowTime.getFullYear();
var month = nowTime.getMonth() + 1;
var day = nowTime.getDate();
var week = fontWeek(nowTime.getDay());
disp.innerText = "今天是:" + year + " 年 " + month + " 月 " + day + " 日 " + week;
}
function fontWeek(week){
switch (week){
case 0: return "星期日";break;
case 1: return "星期一";break;
case 2: return "星期二";break;
case 3: return "星期三";break;
case 4: return "星期四";break;
case 5: return "星期五";break;
case 6: return "星期六";break;
}
}
</script>
</body>
</html>