答案 0 :(得分:1)
根据 @vijayP 的评论尝试此解决方案。如果日期不星期六(6)或星期日(0),则递增日计数器numDays
。
var startDate = new Date('1 Oct 2016');
var endDate = new Date('19 Oct 2016');
var numDays = 0;
while(startDate < endDate)
{
startDate.setDate(startDate.getDate() + 1);
if(startDate.getDay() == 0 || startDate.getDay() == 6)
continue;
numDays = numDays +1;
}
alert(numDays);
答案 1 :(得分:0)
function getWorkingDates(startDate, endDate) {
var curDate = startDate;
var days = [];
while (curDate <= endDate) {
var dayOfWeek = curDate.getDay();
if(!((dayOfWeek == 6) || (dayOfWeek == 0)))
days.push(new Date(curDate));
curDate.setDate(curDate.getDate() + 1);
}
return days;
}
如果您想排除国定假日,您需要有一系列日期。在推送到数组之前,需要检查您的假日数组日期。
function getWorkingDates(startDate, endDate) {
var curDate = startDate;
var days = [];
while (curDate <= endDate) {
var dayOfWeek = curDate.getDay();
if(!((dayOfWeek == 6) || (dayOfWeek == 0))){
if($.inArray(curDate, holidayArray) != -1)
days.push(new Date(curDate));
}
curDate.setDate(curDate.getDate() + 1);
}
return days;
}