Here you can find the source of getWorkDay(Date d1, Date d2, int[] freeDays)
public static int getWorkDay(Date d1, Date d2, int[] freeDays)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getWorkDay(Date d1, Date d2, int[] freeDays) { int dNum = 0; dNum = (int) ((d2.getTime() - d1.getTime()) / 1000 / 60 / 60 / 24) + 1; return dNum - getFreeDay(d1, dNum, freeDays); }//from w w w .ja v a2 s. c o m public static int getWorkDay(Date d1, Date d2) { int[] freeDays = { 0, 6 };//default: Sunday and Saturday are the free days. return getWorkDay(d1, d2, freeDays); } public static int getFreeDay(Date date, int dNum, int[] freeDays) { Calendar cal = Calendar.getInstance(); cal.setTime(date); int start = cal.get(Calendar.DAY_OF_WEEK) - 1; int freeNum = 0; for (int i = 0; i < dNum; i++) { for (int j = 0; j < freeDays.length; j++) { if ((start + i) % 7 == freeDays[j]) { freeNum++; } } } return freeNum; } public static int getFreeDay(Date date, int dNum) { int[] freeDays = { 0, 6 };//default: Sunday and Saturday are the free days. return getFreeDay(date, dNum, freeDays); } }