//设置节假日的数组
var holiday = Array(‘2016-04-30‘,‘2016-05-01‘,‘2016-05-02‘,‘2016-06-09‘,‘2016-06-10‘,‘2016-06-11‘,‘2016-09-15‘,‘2016-09-16‘,‘2016-09-17‘,‘2016-10-1‘,‘2016-10-01‘,‘2016-10-02‘,‘2016-10-03‘,‘2016-10-04‘,‘2016-10-05‘,‘2016-10-06‘,‘2016-10-07‘);
// 全局变量
var fiveDay = Array();//用于保存符合条件的5天的日期
var fiveWeek = Array();//用于保存符合条件的5天的星期
//生成5个符合条件的日期
function get_five_day(){
var index = 0;//用于标记数组已经有的个数
for(var between=1;index<5;between++){
var date = new Date();//Date 对象
date.setDate(date.getDate()+between);
if(date.getDay()==0 || date.getDay()==6 )continue;
var year = date.getFullYear();
var month = date.getMonth()+1;
month = month<10?‘0‘+month:month;
var day = date.getDate();
day = day<10?‘0‘+day:day;
var full_date = year+‘-‘+month+‘-‘+day;
var flag = true;
for(var i = 0;i<holiday.length;i++){//遍历holiday数组
if(full_date == holiday[i]) flag = false;
}
if(flag){
fiveDay[index] = full_date; //存进fiveDay数组
index++;
}
}
}
//将日期转为星期
function changWeek(date_str){
var date = new Date(date_str);
var week_day = date.getDay();
var week_str = ‘‘;
switch(week_day){
case 1:
week_str = ‘周一‘;
break;
case 2:
week_str = ‘周二‘;
break;
case 3:
week_str = ‘周三‘;
break;
case 4:
week_str = ‘周四‘;
break;
case 5:
week_str = ‘周五‘;
break;
}
return week_str;
}
// 转5个日期为星期
function get_five_week_str(){
for(var i=0;i<5;i++){
fiveWeek[i] = changWeek(fiveDay[i]);
}
}
// 执行
get_five_day();
get_five_week_str();
console.log(fiveDay);