Java Day End getMondays(Date startDate, Date endDate)

Here you can find the source of getMondays(Date startDate, Date endDate)

Description

get Mondays

License

Apache License

Declaration

public static List<Date> getMondays(Date startDate, Date endDate) 

Method Source Code

//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();
    }
}

Related

  1. getEndTimeOfDay(Date date)
  2. getEndTimeOfDayOrNow(Date date)
  3. getKalenderWoche(final Date date, final Locale locale)
  4. getLastDayEnding(Date date, int field)
  5. getMinllisBetween(Date beginDate, Date endDate)
  6. getMonthBetween(Date startDate, Date endDate)
  7. getMonthCha(Date start, Date end)
  8. getMonthCount(Date startDate, Date endDate)
  9. getMonthEnd(Date date)