Here you can find the source of getWorkingDaysBetween(Date fromDate, Date toDate)
public static int getWorkingDaysBetween(Date fromDate, Date toDate)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Boeing./* w w w . j a v a 2 s. co m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Boeing - initial API and implementation *******************************************************************************/ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static int getWorkingDaysBetween(Date fromDate, Date toDate) { return getWorkingDaysBetween(getCalendar(fromDate), getCalendar(toDate)); } public static int getWorkingDaysBetween(Calendar fromDate, Calendar toDate) { int workingDays = 0; while (!fromDate.after(toDate)) { int day = fromDate.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { workingDays++; } fromDate.add(Calendar.DATE, 1); } return workingDays; } public static Calendar getCalendar(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } public static String get(Date date) { if (date == null) { return ""; } return DateFormat.getDateInstance().format(date); } public static String get(Date date, String pattern) { return get(date, new SimpleDateFormat(pattern)); } public static String get(Date date, DateFormat dateFormat) { if (date == null) { return ""; } String result = dateFormat.format(date); return result; } }