Here you can find the source of GetLastWorkDayofMonth(String strDateStart)
public static Date GetLastWorkDayofMonth(String strDateStart) throws Exception
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date GetLastWorkDayofMonth(String strDateStart) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Date date_start = sdf.parse(strDateStart); Calendar cal_start = Calendar.getInstance(); cal_start.setTime(date_start);//from w w w . ja va 2s .co m int dayOfWeek = cal_start.get(Calendar.DAY_OF_WEEK) - 1; Date a = new Date(); if (dayOfWeek == 1) { a = AddDate(date_start, -3); } else if (dayOfWeek == 7) { a = AddDate(date_start, -2); } else { a = AddDate(date_start, -1); } // System.out.println(GetFormattedDateUtil(a, "yyyy-MM-dd")); return a; } /** * * @param date * Date * @param days * int * @return Date */ public static Date AddDate(Date date, int days) { Calendar c = Calendar.getInstance(); c.setTime(date); long lTmp = c.getTimeInMillis(); c.setTimeInMillis(lTmp + ((long) days) * 24 * 3600 * 1000); return c.getTime(); } }