Java Week Day getLastWeekday()

Here you can find the source of getLastWeekday()

Description

get Last Weekday

License

Apache License

Declaration

public static Calendar getLastWeekday() 

Method Source Code

//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;
    }
}

Related

  1. getFirstDayOfWeek(String week)
  2. getFriday(Date date)
  3. getLastDayOfCurrWeek()
  4. getLastDayOfWeek(int year, int month)
  5. getLastSundayBeforeThisWeek()
  6. getLastWeekDay(int weekDay)
  7. getLastWeekDay(int weekDay)
  8. getLastWeekMs()
  9. getMon()