获取日历中的日期(6*7 数组)

  monthDay(date) {
    const daysArr = [[], [], [], [], [], []]; // 6*7的日历数组
    const currentWeekday = moment(date).date(1).weekday(); // 获取当月1日为星期几
    const lastMonthDays = moment(date).subtract(1, 'month').daysInMonth(); // 获取上月天数
    const currentMonthDays = moment(date).daysInMonth(); // 获取当月天数
    const getDay = day => (day <= lastMonthDays ? day : (day <= (lastMonthDays + currentMonthDays)) ? day - lastMonthDays : day - (lastMonthDays + currentMonthDays)); // 日期处理
    for (let i = 0; i < 7; i += 1) {
      let virtualDay = (lastMonthDays - currentWeekday) + i + 1;
      for (let j = 0; j < 6; j += 1) {
        daysArr[j][i] = getDay(virtualDay + (j * 7));
      }
    }
    console.table(daysArr);
  }

 

相关文章:

  • 2021-12-18
  • 2022-01-21
  • 2022-02-20
  • 2021-12-18
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2021-04-30
猜你喜欢
  • 2021-04-08
  • 2021-12-29
  • 2021-06-29
  • 2021-11-30
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案