计算星期天除外两个日期和节假日在Javascript阵列之间的天数 [英] Calculate Number of days between two dates excluding sundays and an array of holidays in Javascript

查看:175
本文介绍了计算星期天除外两个日期和节假日在Javascript阵列之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Javascript计算两个日期之间的工作日。

  1日期:2013年4月25日
日期2:2013年5月10日假期:2013年4月27日,2013年5月3日]

我想节假日除外如有如有这两个日期和星期天除外之间存在着总天数。

我都试过,但我不能能够做到这一点的假期阵列。


解决方案

  =差异结束日期 - 开始日期;
VAR假期=新的Array(2013年4月28日,2013年5月22日,2013年6月28日);
idx_holidays = 0;
num_holidays = 0;
而(idx_holidays< holidays.length)
   {
       假期=新的日期(节假日[idx_holidays]);
       如果(DIFF>假期的startDate)
           num_holidays ++;
       idx_holidays ++;
   }

How to Calculate business days between two dates in Javascript.

Say

Date 1 : 04-25-2013
Date 2 : 05-10-2013

Holidays : ["04-27-2013","05-03-2013"]

I want total number of days excluding holidays if any exists between these two dates and excluding sundays if any.

I have tried but I can't be able to do it for holidays array.

解决方案

diff=endDate-startDate;
var holidays=new Array("04-28-2013","05-22-2013","06-28-2013");
idx_holidays=0;
num_holidays=0;
while(idx_holidays < holidays.length)
   {
       holiday=new Date(holidays[idx_holidays]);
       if(diff>holiday-startDate)
           num_holidays++;
       idx_holidays++;
   }

这篇关于计算星期天除外两个日期和节假日在Javascript阵列之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆