Here you can find the source of getDateOfLastSunday(Date d)
public static Date getDateOfLastSunday(Date d)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Date getDateOfLastSunday(Date d) { Calendar c = Calendar.getInstance(); c.setTime(d);//w w w . ja va2s . c o m int weekday = c.get(Calendar.DAY_OF_WEEK); if (weekday != Calendar.SUNDAY) { int days = (Calendar.SUNDAY - weekday) % 7; c.add(Calendar.DAY_OF_YEAR, days); } c.set(Calendar.HOUR, 0); c.set(Calendar.AM_PM, Calendar.AM); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); Date date = c.getTime(); return date; } }