Here you can find the source of endOfWeek(Date inDate, TimeZone timeZone)
Parameter | Description |
---|---|
inDate | The given date. |
public static Calendar endOfWeek(Date inDate, TimeZone timeZone)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**// www . ja v a 2 s. co m * Calculate the start of the week for the given date. * * @param inDate The given date. * * @return The date at the start of the month. */ public static Calendar endOfWeek(Date inDate, TimeZone timeZone) { Calendar c1 = Calendar.getInstance(timeZone); c1.setTime(inDate); Calendar c2 = Calendar.getInstance(timeZone); c2.clear(); int daysToAdd = 8 - isoDayOfWeek(c1.get(Calendar.DAY_OF_WEEK)); c2.set(c1.get(Calendar.YEAR), c1.get(Calendar.MONTH), c1.get(Calendar.DAY_OF_MONTH) + daysToAdd); return c2; } private static int isoDayOfWeek(int javaDayOfWeek) { switch (javaDayOfWeek) { case Calendar.MONDAY: return 1; case Calendar.TUESDAY: return 2; case Calendar.WEDNESDAY: return 3; case Calendar.THURSDAY: return 4; case Calendar.FRIDAY: return 5; case Calendar.SATURDAY: return 6; case Calendar.SUNDAY: return 7; default: throw new IllegalArgumentException("Invalid day of week " + javaDayOfWeek); } } }