Here you can find the source of getLastDayOfWeek(Date date)
public static Date getLastDayOfWeek(Date date)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date getLastDayOfWeek(Date date) { Calendar c = new GregorianCalendar(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setTime(date);// w w w . j a va2 s.c o m c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); return c.getTime(); } public static Date getLastDayOfWeek(int year, int week) { Calendar calLast = Calendar.getInstance(); calLast.set(year, 0, 7); Date firstDate = getLastDayOfWeek(calLast.getTime()); Calendar firstDateCal = Calendar.getInstance(); firstDateCal.setTime(firstDate); Calendar c = new GregorianCalendar(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DATE, firstDateCal.get(Calendar.DATE)); Calendar cal = (GregorianCalendar) c.clone(); cal.add(Calendar.DATE, (week - 1) * 7); Date lastDate = getLastDayOfWeek(cal.getTime()); return lastDate; } public static Date getFirstDayOfWeek(Date date) { Calendar c = new GregorianCalendar(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setTime(date); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); return c.getTime(); } public static Date getFirstDayOfWeek(int year, int week) { Calendar calFirst = Calendar.getInstance(); calFirst.set(year, 0, 7); Date firstDate = getFirstDayOfWeek(calFirst.getTime()); Calendar firstDateCal = Calendar.getInstance(); firstDateCal.setTime(firstDate); Calendar c = new GregorianCalendar(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DATE, firstDateCal.get(Calendar.DATE)); Calendar cal = (GregorianCalendar) c.clone(); cal.add(Calendar.DATE, (week - 1) * 7); firstDate = getFirstDayOfWeek(cal.getTime()); return firstDate; } }