Here you can find the source of getWeekDaysBetween(Date fromDate, Date toDate, int dayOfWeek)
public static int getWeekDaysBetween(Date fromDate, Date toDate, int dayOfWeek)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { private static final int DAYS_IN_A_WEEK = 7; public static int getWeekDaysBetween(Date fromDate, Date toDate, int dayOfWeek) { int result = 0; Date firstDate = getFirstWeekdayBetween(fromDate, toDate, dayOfWeek); if (firstDate == null) { return 0; }//from www . ja v a2s .c o m Calendar aDay = Calendar.getInstance(); aDay.setTime(firstDate); while (aDay.getTime().before(toDate)) { result++; aDay.add(Calendar.DATE, DAYS_IN_A_WEEK); } return result; } public static Date getFirstWeekdayBetween(Date fromDate, Date toDate, int dayOfWeek) { Calendar aDay = Calendar.getInstance(); aDay.setTime(fromDate); while (aDay.getTime().before(toDate)) { if (aDay.get(Calendar.DAY_OF_WEEK) == dayOfWeek) { return aDay.getTime(); } aDay.add(Calendar.DATE, 1); } return null; } }