在您当前代码的逻辑中,它应该类似于
myDate.setDate(myDate.getDate() + plusdays + skipdays)
计算skipdays
使用
var singleDay = 1000 * 60 * 60 * 24,
fromdate = new Date('1 Apr 2012'),
todate = new Date('15 Apr 2012'),
skipdays = (todate - fromdate) / singleDay ;
更新
发表评论后,您可以使用
function interSectionInDays(include, exclude){
if (!(include.from > exclude.to) && !(include.to < exclude.from)){
var from = Math.max(include.from, exclude.from),
to = Math.min(include.to, exclude.to),
singleDay = 1000 * 60 * 60 * 24;
return (to-from)/singleDay;
}
return 0;
}
此方法将计算日期范围之间的相交天数..
用于
interSectionInDays( {from: <startdate>, to:<enddate>}, {from:<excludestartdate>, to:<excludeenddate>} );
所以在你的例子中
var fromdate = new Date(myDate),
todate = new Date(fromdate).setDate( fromdate.getDate() + plusdays),
excludestart = new Date('1 Jan 2012'),
excludeend = new Date('5 Apr 2012'),
skipdays = interSectionInDays( {from:fromdate, to:todate}, {from:excludestart, to:excludeend});
myDate.setDate( myDate.getDate() + plusdays + skipdays );
演示在 http://jsfiddle.net/gaby/mACmW/