JS生成日历
版权声明:本文为博主前端基础文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8">
<title>Document</title> <style> #box { font-size: 50px; color: red; } </style> </head>
<body> <div id="box"></div> <script> function getToday() { var week = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; var box = document.getElementById("box"); var today = new Date();
var yy = today.getFullYear();
var mm = todouble(today.getMonth() + 1);
var dd = todouble(today.getDate());
var hh = todouble(today.getHours());
var MM = todouble(today.getMinutes());
var ss = todouble(today.getSeconds());
var ee = today.getDay();
var dddd = yy + "年" + mm + "月" + dd + "日" + " " + hh + ":" + MM + ":" + ss + " " + week[ee];
box.innerHTML = dddd; }
getToday(); var timer = setInterval(getToday, 1000);
function todouble(n) { return n < 10 ? "0" + n : "" + n; }
</script> </body>
</html>
|