Here you can find the source of getLastWeekday()
public static Calendar getLastWeekday()
//package com.java2s; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright 2013 Joseph Yuan/*ww w.j a v a2 s. co m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import java.util.Calendar; public class Main { public static Calendar getLastWeekday() { return getLastWeekday(getYesterday()); } public static Calendar getLastWeekday(Calendar date) { Calendar _date = Calendar.getInstance(); _date.setTime(date.getTime()); while (isWeekend(_date)) { _date.add(Calendar.DATE, -1); } return _date; } public static Calendar getYesterday() { Calendar date = Calendar.getInstance(); date.add(Calendar.DATE, -1); return date; } public static boolean isWeekend(Calendar date) { return date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; } }