Here you can find the source of getMondayDate(String date)
public static String getMondayDate(String date)
//package com.java2s; import java.util.Calendar; public class Main { public static String getMondayDate(String date) { String startDate;/*from w w w. j a v a 2 s . c o m*/ int year = getYear(date); int month = getMonth(date); int day = getDate(date); int curDayOfWeek = getDayOfWeek(year, month, day); int startTmp = 2 - curDayOfWeek; if (startTmp == 0) return date; if (startTmp > 0) { startTmp = startTmp - 7; } Calendar tmpCalendar = Calendar.getInstance(); tmpCalendar.set(year, month - 1, day); tmpCalendar.add(Calendar.DATE, startTmp); startDate = Integer.toString(tmpCalendar.get(Calendar.YEAR)); if ((tmpCalendar.get(Calendar.MONTH) + 1) < 10) startDate += "0"; startDate += Integer.toString((tmpCalendar.get(Calendar.MONTH)) + 1); if (tmpCalendar.get(Calendar.DATE) < 10) startDate += "0"; startDate += Integer.toString(tmpCalendar.get(Calendar.DATE)); return startDate; } public static int getYear(String date) { return Integer.parseInt(date.substring(0, 4)); } public static int getMonth(String date) { return Integer.parseInt(date.substring(4, 6)); } public static int getDate(String date) { return Integer.parseInt(date.substring(6, 8)); } public static int getDayOfWeek(int _year, int _month, int _day) { int year, month, date; Calendar cal = Calendar.getInstance(); cal.set(_year, _month - 1, _day); return cal.get(Calendar.DAY_OF_WEEK); } }