久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

計算包括節(jié)假日在內的工作日

calculate business days including holidays(計算包括節(jié)假日在內的工作日)
本文介紹了計算包括節(jié)假日在內的工作日的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我需要計算兩個日期之間的工作日.例如:我們在 7 月 4 日放假(在美國).所以如果我的日期是日期 1 = 07/03/2012日期 2 = 07/06/2012

i need to calculate the business days between two dates. ex : we have holiday(in USA) on july4th. so if my dates are date1 = 07/03/2012 date2 = 07/06/2012

由于 7 月 4 日是假期,因此這些日期應該是 1 個工作日.

no of business days b/w these dates should be 1 since july4th is holiday.

我有一個下面的方法來計算工作日,它只計算周末而不是假期.還有什么方法可以計算假期....請幫助我.

i have a below method to calclulate the business days which will only counts week ends but not holidays. is there any way to calculate holidays also....please help me on this.

  public static int getWorkingDaysBetweenTwoDates(Date startDate, Date endDate) {  
    Calendar startCal;  
    Calendar endCal;  
    startCal = Calendar.getInstance();  
    startCal.setTime(startDate);  
    endCal = Calendar.getInstance();  
    endCal.setTime(endDate);  
    int workDays = 0;  

    //Return 0 if start and end are the same  
    if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {  
        return 0;  
    }  

    if (startCal.getTimeInMillis() > endCal.getTimeInMillis()) {  
        startCal.setTime(endDate);  
        endCal.setTime(startDate);  
    }  

    do {  
        startCal.add(Calendar.DAY_OF_MONTH, 1);  
        if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY   
       && startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {  
            ++workDays;  
        }  
    } while (startCal.getTimeInMillis() < endCal.getTimeInMillis());  

    return workDays;  
}

推薦答案

假設您有一個包含所有假期的列表,正如您所提到的.

Let's pretend you have a list containing all the holidays, as you mentioned.

ArrayList<Integer> holidays = ...

只需在 do-while 中為 if 條件添加一個條件:

Just add a condition to your if condition in your do-while:

do {
          startCal.add(Calendar.DAY_OF_MONTH, 1);
          if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
          && startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY
          && !holidays.contains((Integer) startCal.get(Calendar.DAY_OF_YEAR))) {
              ++workDays;
          }
} while (startCal.getTimeInMillis() < endCal.getTimeInMillis());

為簡單起見,我假設 holiday 包含格式與 Calendar.DAY_OF_YEAR 相同的日期.

For simplicity's sake, I've assumed holiday contains dates in the format identical to Calendar.DAY_OF_YEAR.

這篇關于計算包括節(jié)假日在內的工作日的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 日韩精品一区二区三区中文在线 | 亚洲精品久久久一区二区三区 | 视频一区二区中文字幕 | 精品欧美 | 欧美一区二区久久 | 国产亚洲久 | 人人九九精 | 国产精品日本一区二区在线播放 | 成人免费网视频 | 亚洲一区国产精品 | 免费精品 | 中文天堂网 | 中文字幕av网站 | 欧美成人免费在线视频 | 一区二区三区国产好 | 国产一级片在线播放 | 日本黄色影片在线观看 | 日韩午夜精品 | 久久成人免费视频 | 色综合一区二区 | 超碰免费在 | 精品久久久久久久久久 | 亚洲精品专区 | 久草网免费 | 日韩伦理一区二区 | 日产久久| 黄色网络在线观看 | 午夜影院在线观看免费 | 日本a视频 | 日本精品视频 | 亚洲综合天堂网 | 精品国产网 | 99精品免费久久久久久久久日本 | 国产露脸国语对白在线 | 欧美aaaaa | 亚洲精品av在线 | 久久专区| 男人的天堂在线视频 | 欧美精品久久 | 成人精品鲁一区一区二区 | 日本一区二区在线视频 |