Find the sample program that may cater your need. You should be able to enhance
it further. For better understanding, refer Calendar, GregorianCalendar classes.
--------------------------
import java.util.Calendar;
import java.util.GregorianCalendar;
public class WorkingDayCalc {
public static void main(String args[]) {
int sYear = 2004,sMonth = 11,sDate = 30;
int eYear = 2005,eMonth = 0,eDate = 3;
Calendar startDate = new GregorianCalendar(sYear,sMonth,sDate);
Calendar endDate = new GregorianCalendar(eYear,eMonth,eDate);
int startDayOfYear = startDate.get(startDate.DAY_OF_YEAR);
int endDayOfYear = endDate.get(endDate.DAY_OF_YEAR);
int totalNumberOfDays = 0;
// Adding one to include both start and end dates.
if(eYear > sYear) {
totalNumberOfDays =
(startDate.getMaximum(startDate.DAY_OF_YEAR)-startDayOfYear)+endDayOfYear + 1;
} else {
totalNumberOfDays = endDayOfYear-startDayOfYear + 1;
}
int numberOfWorkingDays = 0;
for(int i=0;i<totalNumberOfDays;i++) {
if(startDate.get(startDate.DAY_OF_WEEK)!=1 &&
startDate.get(startDate.DAY_OF_WEEK)!=7) {
numberOfWorkingDays++;
}
startDate.add(Calendar.DATE,1);
}
System.out.println("NumberOfWorkingDays : " + numberOfWorkingDays);
System.out.println("TotalNumberOfDays : " + totalNumberOfDays);
}
}