I'm trying to create a list of dates that are included between two dates. Here is how I tried to do it :
public void fillDates() {
long diffInMillis = Math.abs(secondDate.getTime() - firstDate.getTime());
long diff = TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS);
for (int i=0; i <= diff; i++) {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.DAY_OF_MONTH)+i);
Long date = calendar.getTime().getTime();
String str = convertDate(date);
dates.add(str);
}
}
dates
is a list of strings, and convertDate()
is converting a long
date into a string date. But I think the problem comes from the lines above, as the same day is added to the list every time.
I know other similar questions exists, but I didn't find any that really helped me... But if you have an entirely different solution for me, don't hesitate ! I'm just trying to get a list of (string) dates between two dates that are submitted by the user through Date Pickers
.