Here you can find the source of getWeekBegin(Date date)
public static Date getWeekBegin(Date date)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date getWeekBegin(Date date) { return getWeekBegin(date, 0); }/* www . j a va 2 s . co m*/ public static Date getWeekBegin(Date date, Integer day) { Calendar c = Calendar.getInstance(); c.setTime(date); int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1; if (day_of_week == 0) { day_of_week = 7; } c.add(Calendar.DATE, -day_of_week + 1 + day); return stringToDate(dateToString(c.getTime(), "yyyy-MM-dd") + " 00:00:00", "yyyy-MM-dd HH:mm:ss"); } public static Date stringToDate(String dateString) { return stringToDate(dateString, "yyyy-MM-dd HH:mm:ss"); } public static Date stringToDate(String dateString, String pattern) { SimpleDateFormat simpledateformat = new SimpleDateFormat(pattern); Date date = new Date(); try { date = simpledateformat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; } public static String dateToString(Date date, String pattern) { if (date != null) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); return sdf.format(date); } return ""; } public static String dateToString(Date date) { return dateToString(date, "yyyy-MM-dd HH:mm:ss"); } }