javascript 模拟日历

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div {
width: 800px;
margin: 200px auto;
color: orange;
text-align: center;
font: 600 30px/30px "simSun";
}
</style>
</head>
<body>
<div></div> <script>
//模拟日历需求:每天打开页面都能定时显示年月日和星期几
//步骤:创建一个当前日期的日期对象,获取其中的年月日和星期,赋值给div //1.创建一个当前日期的日期对象
var date = new Date();
//2.获取其中的年月日和星期
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var week = date.getDay();
// console.log(year+" "+month+" "+day+" "+week);
//3.赋值给div
var arr =["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var div = document.getElementsByTagName("div")[0];
div.innerText = "今天是:"+year+"年"+(month+1)+"月"+day+"日"+arr[week];
</script>
</body>
</html>
上一篇:洛谷 P4114 Qtree1


下一篇:树链剖分详解(洛谷模板 P3384)