前言:day.js 获取(当前)月份的方法

函数:

function getDaysArrayByMonth() {
  //获取当前月份包含的天数
  var daysInMonth = dayjs().daysInMonth();
  var arrDays = [];

  //循环获取月份里的日期
  while(daysInMonth) {
    var current = dayjs().date(daysInMonth);
    arrDays.push(current);
    daysInMonth--;
  }

  return arrDays;
}

调用:

var schedule = getDaysArrayByMonth();
console.log(schedule)
schedule.forEach(function(item) {
console.log(item.format("DD/MM"));
});

输出:

(adsbygoogle = window.adsbygoogle || []).push({});