Here you can find the source of calculateBusinessDays(Date startDate, Date endDate, int firstWeekendDay, int secondWeekendDay)
public static int calculateBusinessDays(Date startDate, Date endDate, int firstWeekendDay, int secondWeekendDay)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int calculateBusinessDays(Date startDate, Date endDate, int firstWeekendDay, int secondWeekendDay) { Calendar startCal = Calendar.getInstance(); startCal.setTime(startDate);/*from w ww. j a va 2s . co m*/ Calendar 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) != firstWeekendDay && startCal.get(Calendar.DAY_OF_WEEK) != secondWeekendDay) { workDays++; } } while (startCal.getTimeInMillis() <= endCal.getTimeInMillis()); return workDays; } }