阅读背景:

javascript 实现日历:生成日历数组

来源:互联网 

 

  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);
  }  initCalendar() {
    const now = n



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: