java get difference days without weekends

Solutions on MaxInterview for java get difference days without weekends by the best coders in the world

showing results for - "java get difference days without weekends"
Patty
05 Jun 2019
1DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
2    Date date1 = df.parse("10/08/2013");
3    Date date2 = df.parse("21/08/2013");
4    Calendar cal1 = Calendar.getInstance();
5    Calendar cal2 = Calendar.getInstance();
6    cal1.setTime(date1);
7    cal2.setTime(date2);
8
9    int numberOfDays = 0;
10    while (cal1.before(cal2)) {
11        if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))
12           &&(Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {
13            numberOfDays++;
14        }
15        cal1.add(Calendar.DATE,1);
16    }
17    System.out.println(numberOfDays);
18