Here you can find the source of getMonday(String date)
public static String getMonday(String date)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static String getMonday(String date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd"); Date d = null;//from w w w . ja v a 2s.com try { d = format.parse(date); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(d); int days = cal.get(Calendar.DAY_OF_WEEK); if (days == 1) { days = 1; String preMonday = getPreviousMonday(d, days); System.out.println("preMonday" + preMonday); return preMonday; } else { cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return format2.format(cal.getTime()); } } public static String getPreviousMonday(Date date, int days) { int weeks = -1; GregorianCalendar currentDate = new GregorianCalendar(); currentDate.setTime(date); currentDate.add(GregorianCalendar.DATE, days + 7 * weeks); Date monday = currentDate.getTime(); DateFormat df = DateFormat.getDateInstance(); String preMonday = df.format(monday); return preMonday; } }