周末及节假日天数去掉

Posted web-前端工程师

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了周末及节假日天数去掉相关的知识,希望对你有一定的参考价值。

//除去节假日 周末   计算工作日
var holiday= [‘2018-05-10‘];
var holidayMap={};
function getMap(hd){
for(var i=0;i<hd.length;i++){
holidayMap[hd[i]]=‘1‘;
}
}
function formatTen(f){
if (parseInt(f,10)<10){
return ‘0‘+f;
}
return f;
}
function formateDate(date){
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
return year + "-" + formatTen(month) + "-" + formatTen(day);
}
function getworkday(dat,itervalByDay){
var str=dat.split("-");
var date=new Date();
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
date.setUTCHours(0, 0, 0, 0);
var millisceonds =date.getTime();
for(var i=1;i<=itervalByDay;i++){
millisceonds +=24*60*60*1000;
date.setTime(millisceonds);
if(date.getDay()==0||date.getDay()==6){
i--;
}else{//过滤节假日
var d=formateDate(date);
if(holidayMap[d]){
i--;
}
}
}
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var rq = year + "-" + formatTen(month) + "-" + formatTen(day);
return rq;
}
function getNowFormatStates() {
var date = new Date();
var seperator1 = "-";
var strDate = date.getDate();
var month = parseInt(date.getMonth()) + 1;
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var strDate = parseInt(strDate);
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
return currentdate;
}
getMap(holiday);
var r = getworkday(getNowFormat(),3);

以上是关于周末及节假日天数去掉的主要内容,如果未能解决你的问题,请参考以下文章

计算每月的业务/活跃天数

java 给一个日期,往后加三天,如果是周末,节假日不算天数。直到加满三天为之,得出日期。

每个季度执行相等的天数 R 'xts'

oracle怎么计算两个日期之间去除周末的天数?

中国法定节假日天数以及世界各国放假天数

中国法定节假日天数以及世界各国放假天数