Javascript 如何通过提供天数间隔在两个日期之间创建日期事件?
我有以下数据: 1年合同Javascript 如何通过提供天数间隔在两个日期之间创建日期事件?,javascript,jquery,date,datepicker,Javascript,Jquery,Date,Datepicker,我有以下数据: 1年合同 Start Date: 01-01-2019 End Date: 31-12-2019 开始日期和结束日期之间的15天间隔不包括所有星期五 准确的预期产出不包括所有周五 19-01-2019 //exclude Fridays then got 19 jan 2019 ----------- 05-02-2019 //after 15 days ----------- 23-02-2019 //after 15 days ------------- keep on
Start Date: 01-01-2019
End Date: 31-12-2019
开始日期和结束日期之间的15天间隔不包括所有星期五
准确的预期产出不包括所有周五
19-01-2019 //exclude Fridays then got 19 jan 2019
-----------
05-02-2019 //after 15 days
-----------
23-02-2019 //after 15 days
-------------
keep on adding.. hit until end month 12-2019
如何生成它?有没有更好的方法
var start = new Date("2019-01-01");
var end = new Date("2019-12-31");
while (start <= end) {
console.log( new Date(start) );
start.setMonth( start.getMonth() + 1 );
}
var开始=新日期(“2019-01-01”);
var结束=新日期(“2019-12-31”);
虽然(从您的用例开始,但似乎星期五是非工作日,您希望根据开始日期打印第15天
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date; }
function printNextPeriod(startDate, endDate, periodInDays) {
var numWorkDays = 0;
var currentDate = new Date(startDate);
while (numWorkDays < periodInDays && currentDate <= endDate) {
currentDate = currentDate.addDays(1);
// Skips friday
if (currentDate.getDay() !== 5) {
numWorkDays++;
}
if (numWorkDays == periodInDays) {
numWorkDays = 0;
console.log(currentDate);
}
} }
Date.prototype.addDays=函数(天){
var date=新日期(this.valueOf());
date.setDate(date.getDate()+天);
返回日期;}
函数printNextPeriod(开始日期、结束日期、周期天数){
var numWorkDays=0;
var currentDate=新日期(起始日期);
虽然(numWorkDays