请问js如何选出未来20天的工作日抽取出来?
这样可以实现排班表了……
来自酷炫的 CNodeMD
3 回复
剔除工作日,打印出时间……
来自酷炫的 CNodeMD
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));