Here you can find the source of getDayInWeekBeginAndEnd(Date date)
public static String[] getDayInWeekBeginAndEnd(Date date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String[] getDayInWeekBeginAndEnd(Date date) { java.util.Calendar cal = java.util.Calendar.getInstance(); cal.setTime(date);//from w w w. j ava2 s . com int week = cal.get(java.util.Calendar.DAY_OF_WEEK) - 1; String begin, end; if (week == 0) { begin = addDate(date, -6); end = format(date); } else { int days = 7 - week; begin = addDate(date, -(week - 1)); end = addDate(date, days); } return new String[] { begin, end }; } public static String addDate(Date date, int k) { java.util.Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, k); return format(cal.getTime()); } public static String format(Date date, String pattern) { if (date == null) { return null; } SimpleDateFormat sf = new SimpleDateFormat(pattern); return sf.format(date); } public static String format(Date date) { return format(date, "yyyy-MM-dd"); } }