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

計(jì)算包括節(jié)假日在內(nèi)的工作日

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

我需要計(jì)算兩個(gè)日期之間的工作日.例如:我們?cè)?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 日是假期,因此這些日期應(yīng)該是 1 個(gè)工作日.

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

我有一個(gè)下面的方法來計(jì)算工作日,它只計(jì)算周末而不是假期.還有什么方法可以計(jì)算假期....請(qǐng)幫助我.

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;  
}

推薦答案

假設(shè)您有一個(gè)包含所有假期的列表,正如您所提到的.

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

ArrayList<Integer> holidays = ...

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

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());

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

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

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

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 国产午夜在线观看 | 欧美在线一区二区三区 | 性色av网站 | 国产精品一区一区三区 | 黄色免费毛片 | 99视频在线观看免费 | 久久精品区 | 欧美精品三区 | 日本加勒比在线观看 | 成人免费毛片果冻 | 国产区一区 | 亚洲精品久久久久久久久 | 97人人看 | 在线午夜视频 | 免费黄色片视频 | 五月婷婷在线播放 | 日韩在线资源 | 狠狠干在线 | 午夜精品久久久久久久久久蜜桃 | 中文字幕丰满人伦在线 | 色婷婷狠狠 | 欧美久久精品 | 四虎精品视频 | 一级片日韩 | 黄色片aaa | 国产一级在线视频 | 在线播放一区 | 诱人的大乳奶3做爰 | 婷色| 欧美福利一区二区 | 婷婷在线视频 | 欧美日韩高清在线 | 三级在线观看视频 | 国产天堂网 | 日韩av一级片 | 亚洲三级小说 | 欧洲一级片 | 黄色av毛片 | 欧美性猛交xxxx黑人交 | 黄色一级片网站 | 日韩在线免费观看视频 |