/* 获取时间段内属于星期一(*)的日期们
* begin: 开始时间
* end:结束时间
* weekNum:星期几 {number}
*/
function getWeek (begin, end, weekNum){
var dateArr = new Array();
var stimeArr = begin.split("-");//=>["2018", "01", "01"]
var etimeArr = end.split("-");//=>["2018", "01", "30"]
var stoday = new Date();
stoday.setUTCFullYear(stimeArr[0], stimeArr[1]-1, stimeArr[2]);
var etoday = new Date();
etoday.setUTCFullYear(etimeArr[0], etimeArr[1]-1, etimeArr[2]);
var unixDb = stoday.getTime();//开始时间的毫秒数
var unixDe = etoday.getTime();//结束时间的毫秒数
for (var k = unixDb; k <= unixDe;) {
let needJudgeDate = msToDate(parseInt(k)).withoutTime;
//不加这个if判断直接push的话就是已知时间段内的所有日期
if (new Date(needJudgeDate).getDay() === weekNum) {
dateArr.push(needJudgeDate);
}
k = k + 24*60*60*1000;
}
return dateArr;
}
获取时间段内属于星期一(*)的日期们
最新推荐文章于 2022-09-01 10:28:06 发布