How can I add business days to the current date in Java?

后端 未结 14 1377
Happy的楠姐
Happy的楠姐 2020-12-03 02:05

How can I add business days to the current date in Java?

public Calendar addBusinessDate(Calendar cal, int days) {
//
// code goes over here
//
}
         


        
14条回答
  •  Happy的楠姐
    2020-12-03 02:45

    /* To Calculate 10 business days ahead of today's date
    */
    public class DueDate {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            DueDate d = new DueDate();
            String dueDate = d.getDueDate(10);
            System.out.println("due Date " + dueDate);
        }
        public String getDueDate(int bday){
            Calendar cal = new GregorianCalendar();
            SimpleDateFormat fdate = new SimpleDateFormat("MM/dd/yyyy");
            while(bday > 0){
                cal.add(Calendar.DAY_OF_MONTH, 1);
                if(noWeekendsorHolidays(cal)){
                    bday--;
                }
            }
            return fdate.format(cal.getTime());
        }
    
        public boolean noWeekendsorHolidays(Calendar cal){
            int day = cal.get(Calendar.DAY_OF_WEEK);
            if(day == 1 || day == 7){
                return false;
            }
            return true;
        }
    
    }
    

提交回复
热议问题