initCalendar() {
const now = new Date();
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
const endDay = new Date(
now.getMonth() === 11
? new Date(now.getFullYear() + 1, 0, 1).getTime() - 8640000
: new Date(now.getFullYear(), now.getMonth() + 1, 1).getTime() -
8640000);
let month = now.getMonth() + 1; // 全局月
let row = 0;
let col = firstDay.getDay();
const calendar = [[]];
let thisDay = 1;
const end = endDay.getDate();
console.log(end);
while (thisDay <= end) {
if (col === 7) {
row ++;
col = 0;
calendar[row] = [thisDay];
} else {
calendar[row][col] = thisDay;
}
thisDay++;
col ++;
}
console.log(calendar);
}
javascript 实现日历:生成日历数组
猜你喜欢
转载自blog.csdn.net/u013475983/article/details/93767687
今日推荐
周排行