Java Day of Week getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek)

Here you can find the source of getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek)

Description

get All Days Date Between

License

Apache License

Declaration

public static List<Date> getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.time.DayOfWeek;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main {
    public static List<Date> getAllDaysDateBetween(Date startDate, Date endDate, DayOfWeek dayOfWeek) {
        Calendar startCal = Calendar.getInstance();
        startCal.setTime(startDate);//w  w w .  ja v a 2s .c om
        Calendar endCal = Calendar.getInstance();
        endCal.setTime(endDate);

        ArrayList<Date> daysDateList = new ArrayList<>();

        while (!startCal.equals(endCal)) {
            startCal.add(Calendar.DATE, 1);
            if (startCal.get(Calendar.DAY_OF_WEEK) == dayOfWeek.getValue()) {
                daysDateList.add(startCal.getTime());
            }
        }
        return daysDateList;
    }
}

Related

  1. endOfWeek(Date inDate, TimeZone timeZone)
  2. extractDayOfWeek(Date date)
  3. findDayOfWeek(String threeLetters)
  4. firstDateAfterAddWeeks(Date early, int weeks)
  5. firstDayOfWeek()
  6. getBounceDateofWeek(Date date)
  7. getDateByWeek(int week)
  8. getDateByYearAndWeekNum(int year, int weekNum)
  9. getDateForCurrentWeekDay(int day)