So I've been using the Java Streams API, and I'm trying to filter dates in my DB, in which the start date of something is before the current date, and the end date is after the current date. I've tried multiple things, but nothing I've tried so far seems to work.
Here's what I've tried so far:
I've tried implementing the
ChronoLocalDate
interface, and used.isBefore() and
.isAfter()`, but the dates did not filter properlyAt this point I've now tried sticking with
LocalDate
, and I've tried convertingLocalDate.now()
to theyyyy-MM-dd
format (which is the date format in my DB) using the following code:
LocalDate rightNow = LocalDate.now();
String formatString = rightNow.format(DateTimeFormatter.ISO_LOCAL_DATE);
However, this doesn't work and results in the following error:
The method format(DateTimeFormatter) is undefined for the type LocalDate
I got the above code from various 2018 examples. Is LocalDate.format()
already depreciated?
Also, I haven't been able to find any relevant examples for filtering between a start date and end date using LocalDate.
Any help from here would be greatly appreciated. Thanks in advance.
So I found out what was wrong. I was importing the wrong LocalDate
from java.joda
instead of java.time
.
So from here, I'm not using ChronoLocalDate
anymore, but the LocalDate
from java.time
, and my filtering now works perfectly. Very silly mistake on my part, but I figured it out.
Thank you everyone who also tried to help.