[英]How to skip 2nd and 4th Saturday between 2 dates using java script or jquery
I have requirement as follows I have two dates i need to skip 2nd and 4th saturdays and sundays between the dates.我有如下要求我有两个日期我需要跳过日期之间的第二个和第四个星期六和星期日。 for example Date1: 01/12/2017 Date2: 11/12/2017 output :8 days are weekends
例如 Date1: 01/12/2017 Date2: 11/12/2017 输出:8 天是周末
Thanks Chakri谢谢查克里
var lock = false;
if(('currentdate' = 'saturday') || ('currentdate' = 'sunday')){
if(lock=false){
//do some code here
lock=true;
} else {
//do some code here whatever you gonna do at 2nd and 4th weekend
lock = false;
}
}
This will let you to do your base code on 1st and 3rh weekends and then you will lock it for next time.这将让您在第 1 个和第 3 个周末完成基本代码,然后您将锁定它以备下次使用。 2nd and 4th will be doing the else code what ever it is.
2nd 和 4th 将执行 else 代码,无论它是什么。
var totalSaturday = 0;
var totalSundays = 0;
for (var i = fromDate; i <= toDate;) {
if (i.getDay() == 0) {
totalSundays++;
}
if (i.getDay() == 6) {
var day=i.getDate() / 7;
var week = Math.floor(day);
if(day.toString().indexOf('.')==1)
{
if(week =="1" || week == "3"){
totalSaturday++;
}
}
else
{ if(week =="2" || week == "4"){
totalSaturday++;
}
}
}
i.setTime(i.getTime() + 1000 * 60 * 60 * 24);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.