function allWeeks(now_month) {
let week_array = [];
let today = new Date(Date.parse(now_month));
let year = today.getFullYear();
let month = today.getMonth();
let i = 0;
let start = new Date(year, month, 1); // 得到当月第一天
let end = new Date(year, month+1, 0); // 得到当月最后一天
let start_day = start.getDay(); // 当月第一天是周几
switch(start_day)
{
case 0: i = -5; break;
case 1: i = 1; break;
case 2: i = 0; break;
case 3: i = -1; break;
case 4: i = -2; break;
case 5: i = -3; break;
case 6: i = -4; break;
}
while ( new Date(year, month, i) <= end) {
week_array.push([ new Date(year, month, i).format("yyyy-MM-dd"),new Date(year, month, i + 6).format("yyyy-MM-dd")])
i += 7;
}
return week_array;
}
allWeeks('2019-12')
获取一个月有多少个周
最新推荐文章于 2023-01-15 20:35:45 发布