Here you can find the source of getEndOfWeek(Date date)
Parameter | Description |
---|---|
date | to get the end of week for |
public static Date getEndOfWeek(Date date)
//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; } }