Here you can find the source of fillBetweenDays(Date from, Date to)
public static Set<Date> fillBetweenDays(Date from, Date to)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Set; import java.util.TreeSet; public class Main { public static Set<Date> fillBetweenDays(Date from, Date to) { Calendar c1 = dateToCalendar(from); Calendar c2 = dateToCalendar(to); int days = gapInDays(c1, c2); Set<Date> fill = new TreeSet<>(); if (days > 0) { for (int i = 1; i < days; i++) { c1.add(Calendar.DAY_OF_MONTH, 1); fill.add(c1.getTime());// www . ja v a 2s . co m } } return fill; } public static Calendar dateToCalendar(Date d) { Calendar c1 = new GregorianCalendar(); c1.setTime(d); return c1; } static int gapInDays(Calendar a, Calendar b) { //same year if (a.get(Calendar.YEAR) == b.get(Calendar.YEAR)) { return b.get(Calendar.DAY_OF_YEAR) - a.get(Calendar.DAY_OF_YEAR); } //consecutive year else if (a.get(Calendar.YEAR) + 1 == b.get(Calendar.YEAR)) { return a.getMaximum(Calendar.DAY_OF_YEAR) + b.get(Calendar.DAY_OF_YEAR) - a.get(Calendar.DAY_OF_YEAR); } else return 0; } }