JavaScript以固定的天数自动填充工作日

时间:2018-03-16 12:41:52

标签: javascript asp.net

我需要一些javascript的帮助。我有这个javascript函数,当用户输入开始日期时填充不同间隔的日期。现在,用户只需要填充工作日期(没有周末和假日)。我怎样才能确保在增加天数时它应该只是一个工作日?

我的代码:

function GetModifiedDate(date, noOfDaysAdded) {
        var inputstring = date;
        var dString = inputstring.split('/');
        var dt = new Date(dString[2], dString[0] - 1, dString[1]);
        dt.setDate(dt.getDate() + parseInt(noOfDaysAdded));
        var finaldate = (String(dt.getMonth() + 1)) + '/' + (String(dt.getDate())) + '/' + (String(dt.getFullYear()));
        return finaldate;
    }
function AutoPopulateDatesForLndMgmtCust(obj) {
                var val = obj.value;
                var table = $('#tblLndMgmtCust');
                var rowLength = table[0].rows.length;
                var modifieddate = val;

                     incrementDay = [2, 1, 3, 1, 5, 2, 10, 4, 10, 2, 2, 2, 1, 1];

                for (var i = 0; i < rowLength - 2; i += 1) {
                    var row = table[0].rows[i + 2];
                    var cell = row.cells[2];

                    modifieddate = GetModifiedDate(modifieddate, incrementDay[i] * 1);
                    cell.children[0].children[0].value = modifieddate;
                }
            }

非常感谢!

1 个答案:

答案 0 :(得分:0)

var d = new Date(2018, 03, 16, 0, 0, 0, 0);

var day = d.getDay();
var isWeekend = (day == 6) || (day == 0);    // 6 = Saturday, 0 = Sunday

var day = d.getDay();
var isWorkday = (day != 6) && (day != 0);