I need to check if a date(in string) exists in array list.
I have two dates, first i need to generate date ranges between these two dates and store them in an Array. This is what I am doing.
DateTimeFormatter dateFromatter= DateTimeFormat.forPattern("MM/dd/yyyy");
DateTime startDate= formatter.parseDateTime("01/02/2012");
DateTime endDate= formatter.parseDateTime("01/31/2012");
List<LocalDate> dates = new ArrayList<LocalDate>();
int days = Days.daysBetween(startDate, endDate).getDays();
for (int i=0; i < days; i++) {
This is where i am getting problem.
Type mismatch: cannot convert from DateTime to LocalDate
> LocalDate listOfDates =
> startDate.withFieldAdded(DurationFieldType.days(), i);
> dates.add(listOfDates);
}
Use org.joda.time.Interval
Interval interval = new Interval(startDate, endDate);
for (LocalDate date : dates)
{
if (interval.contains(date))
//
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With