CNode

请问js如何选出未来20天的工作日抽取出来?

问答
Ddpc761218914发布于9 年前最后回复9 年前3 回复3415 浏览0 收藏
这样可以实现排班表了……

来自酷炫的 CNodeMD

查看回复

回复 (3)

D
dpc761218914#1·9 年前

剔除工作日,打印出时间……

来自酷炫的 CNodeMD

G
godghdai#2·9 年前
    Date.DEFAULT_FORMAT_STR = "{year}年{month}月{day}日";
    Date.prototype.format = function(formatStr) {
        var month = (this.getMonth() + 1) + "",
            day = this.getDate() + "",
            date = {
                "year": this.getFullYear(),
                "month": month.length < 2 ? "0" + month : month,
                "day": day.length < 2 ? "0" + day : day
            };
        return Date.replaceTpl(date);
    }
    Date.prototype.isWorkDay = function() {
        //0 Sunday  6 Saturday
        if (this.getDay() == 0 || this.getDay() == 6) return false;
        return true;
    }
    Date.replaceTpl = function(data, formatStr) {
        formatStr = formatStr || Date.DEFAULT_FORMAT_STR;
        return formatStr.replace(/{(\w+)}/g, function(match, $1) { return data[$1]; });
    }
    Date.prototype.futureWorkDateList = function(days) {
        var day = this.getDate() + 1;
        var result = [];
        while (days) {
            var future = new Date();
            future.setDate(day);
            if (future.isWorkDay()) {
                result.push(future.format());
                days--;
            }
            day++;
        }
        return result;
    }
    console.log(new Date().futureWorkDateList(20));
D
dpc761218914#3·9 年前
引用 godghdai

@godghdai 如果我没看错,单单排除周六和周天应该是不行的,还有节假日。刚已经用moment.js 和 节假日数组 实现了~

来自酷炫的 CNodeMD

参与回复
登录后即可参与回复。登录