calendario javascript: generar matriz de calendario

 

  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);
  }

 

Supongo que te gusta

Origin blog.csdn.net/u013475983/article/details/93767687
Recomendado
Clasificación