日历(从今天起后面的14天)
Posted yjgbk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日历(从今天起后面的14天)相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <style> #calender li { list-style: none; table-layout: fixed; } #calender li a { display: table-cell; width: 50px; height: 50px; } </style> <body> <ul id="calender"></ul> </body> <script type="text/javascript" src="js/jQuery-2.1.5.min.js" ></script> <script> function TwoWeekCalender() { var Today = new Date(); var TodayDay = Today.getDate(); var month = Today.getMonth(); var year = Today.getFullYear(); //获取最大天数 var mostDay = new Date(+year, +month + 1, 0).getDate(); var dateArr = []; var distance = mostDay - TodayDay; var thisWeeKDay = Today.getDay(); //星期 var left = 14 - distance; var i; console.log(mostDay,TodayDay,distance,thisWeeKDay,left) for(i = 1; i < thisWeeKDay; i++) { dateArr.push(‘whiteSpace‘); } for(i = 0; i <= distance; i++) { dateArr.push({ Day: year + ‘-‘ + (+month + 1) + ‘-‘ + TodayDay++ }) console.log(i) } if(month == 11) { month = -1; year++; }; for(i = 1; i < left; i++) { dateArr.push({ Day: year + ‘-‘ + (+month + 2) + ‘-‘ + i }) console.log(i) }; console.log(dateArr) var calender_html = ‘<li><a javascript:void()>星期一</a><a javascript:void()>星期二</a><a javascript:void()>星期三</a><a javascript:void()>星期四</a><a javascript:void()>星期五</a><a javascript:void()>星期六</a><a javascript:void()>星期日</a></li><li>‘; dateArr.forEach(function(item, i) { if(i !== 0 && i % 7 == 0) { calender_html += ‘</li><li>‘ } calender_html += item === ‘whiteSpace‘ ? ‘<a javascript:void()></a>‘ : ‘<a javascript:void()>‘ + item.Day + ‘</a>‘; }) calender_html += ‘</li>‘; document.getElementById(‘calender‘).innerHTML = calender_html; } TwoWeekCalender() </script> </html>
14:是代表从今天气到后面的14天,这个值随便(20天,这个值就写20就行)
以上是关于日历(从今天起后面的14天)的主要内容,如果未能解决你的问题,请参考以下文章
从特定时区的给定日期起每 14 天执行一次作业的 Cron 脚本
日历不是从今天开始 jqueryui daterangepicker