Here you can find the source of getMondays(Date startDate, Date endDate)
public static List<Date> getMondays(Date startDate, Date endDate)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; public class Main { public static List<Date> getMondays(Date startDate, Date endDate) { if (endDate != null && !startDate.before(endDate)) { throw new RuntimeException("startDate must before endDate."); }/*from www. j a va 2 s. c om*/ List<Date> mondayList = new ArrayList<Date>(); Date previousMonday = getPreviousMonday(endDate); for (; !previousMonday.before(startDate); previousMonday = getPreviousMonday(previousMonday)) { mondayList.add(previousMonday); } return mondayList; } public static Date getPreviousMonday(Date day) { Calendar previousMonday = Calendar.getInstance(); previousMonday.setTime(day); previousMonday.set(Calendar.HOUR_OF_DAY, 0); previousMonday.set(Calendar.MINUTE, 0); previousMonday.set(Calendar.SECOND, 0); previousMonday.add(Calendar.DATE, -1); previousMonday.add(Calendar.WEEK_OF_MONTH, -1); previousMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return previousMonday.getTime(); } }