简体   繁体   English

如何使用java脚本或jquery跳过2个日期之间的第2个和第4个星期六

[英]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.

相关问题 如何在js Fullcalender中找到第2个和第4个星期六? - How to find 2nd and 4th Saturday in js Fullcalender? 如何使用css或jquery隐藏第2和第4行表? - How to hide the 2nd and 4th table row using css or jquery? jQuery如何获取第二和第三TD内容取决于第四点击 - JQuery how to fetch 2nd and 3rd TD content depend on 4th td click 如何使用while(!feof)仅选择一行的第2个和第4个值? - How to pick only every 2nd and 4th value of a line using while(!feof)? 如何在 Kendodatepicker 中禁用除第 2 周和第 4 周星期四外的所有日期 - How to disable all days in month except 2nd and 4th week's Thursday in Kendodatepicker JavaScript在第二和第四循环中忽略appendChild - JavaScript ignores appendChild in 2nd and 4th loop 如何使用jQuery将元素附加到第四个元素子元素? - How to append element to a 4th element child using jQuery? 使用Javascript自动将日期调整为每月的第2个星期六? - Using Javascript to automatically adjust date to 2nd Saturday of every month? 我的滑块仅显示第1和第3个滑块,但不显示表格的第2和第4个滑块 - My slider only shows 1st and 3rd slider but not the 2nd and 4th slider for table 如果array包含2个相同的对象,则将第二个(或第3个,第4个)对象的值突变 - If array includes 2 objects which are the same, then mutate the 2nd (or 3rd, 4th) object's values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM