Java Day of Week getEndOfWeek(Date date)

Here you can find the source of getEndOfWeek(Date date)

Description

Gets the end of week.

License

Open Source License

Parameter

Parameter Description
date to get the end of week for

Return

end week date.

Declaration

public static Date getEndOfWeek(Date date) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from   w w  w  .j av  a  2 s  .co m*/
     * Gets the end of week.
     *
     * @param date to get the end of week for
     * @return end week date.
     */
    public static Date getEndOfWeek(Date date) {

        return getWeek(date)[1];
    }

    /**
     * Gets the week.
     *
     * @param date the date
     * @return week start and finish date.
     */
    private final static Date[] getWeek(Date date) {

        Date[] period = new Date[2];
        if (date == null) {
            return period;
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        int day = calendar.get(Calendar.DAY_OF_WEEK);
        if (day == Calendar.SUNDAY) {
            period[1] = calendar.getTime();
            calendar.add(Calendar.DAY_OF_WEEK, -6);
            period[0] = calendar.getTime();
        } else {
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            period[0] = calendar.getTime();
            calendar.add(Calendar.DAY_OF_WEEK, 6);
            period[1] = calendar.getTime();
        }

        return period;
    }
}

Related

  1. getDayofWeekForContainedDate(Date dt, DayOfWeek dow)
  2. getDaysByWeek(Integer month, Integer year, Integer week)
  3. getDaysByWeek2(Integer month, Integer year, Integer begin)
  4. getDayWeekDate(String dateStr)
  5. getDayWeekDateStr(Date date)
  6. getFirstDayOfLastWeek(Date date)
  7. getFirstDayOfWeek(int year, int week)
  8. getFirstDayOfWeek(int year, int week)
  9. getFirstDayOfWeek(int year, int week)