简单的js编写日历

日期函数(Date())

    这个函数 (对象) 可以设置我们本地 日期。   年月日 时分秒

   1.创造声明一个新的日期函数   赋值给了  date          var arr = new Array(); 

   2.使用函数:

                        var  date = new Date();  

                        date.getTime();

                        date.valueOf();        得到 距离 1970年的毫秒数

最终效果:

编写HTML,CSS,JS


以下是一个简单的JavaScript日历表代码示例: ```html <!DOCTYPE html> <html> <head> <title>JavaScript Calendar</title> <style> table { border-collapse: collapse; margin: auto; } th, td { padding: 10px; text-align: center; border: 1px solid black; } th { background-color: #ccc; } td:hover { background-color: #f5f5f5; } </style> </head> <body> <h1>JavaScript Calendar</h1> <table> <thead> <tr> <th>Sun</th> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> </tr> </thead> <tbody id="calendar-body"> </tbody> </table> <script> // Get the current date var today = new Date(); // Get the year and month var year = today.getFullYear(); var month = today.getMonth() + 1; // January is 0 // Get the number of days in the current month var daysInMonth = new Date(year, month, 0).getDate(); // Get the first day of the current month var firstDayOfMonth = new Date(year, month-1, 1).getDay(); // Sunday is 0 // Create the calendar table var calendarTable = document.getElementById("calendar-body"); var date = 1; for (var i = 0; i < 6; i++) { var row = document.createElement("tr"); for (var j = 0; j < 7; j++) { if (i === 0 && j < firstDayOfMonth) { var cell = document.createElement("td"); var cellText = document.createTextNode(""); cell.appendChild(cellText); row.appendChild(cell); } else if (date > daysInMonth) { break; } else { var cell = document.createElement("td"); var cellText = document.createTextNode(date); cell.appendChild(cellText); row.appendChild(cell); date++; } } calendarTable.appendChild(row); } </script> </body> </html> ``` 该代码将生成一个简单日历表,显示当前月份的日期。您可以根据需要自定义样式和功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值