How do I compare dates in Java using comparison operators?
Example:
date1 is 30-10-2017
date2 is 31-10-2017
date3 is 30-10-2018
date2 returns false when it should be true that it is less than date3. How can I return true if the date is less than another date and false otherwise?
This is my code:
return (day < theDate.day) || (month < theDate.month) || (year < theDate.year);
Below is my current solution:
{
boolean check = false;
if(year < theDate.year)
{
return true;
}
if(year > theDate.year)
{
return false;
}
if(month < theDate.month)
{
check = true;
}
if(day < theDate.day)
{
check = true;
}
else
{
return false;
}
return check;
}
LocalDateAPI along with theisBeforeandisAftermethods.java.util.Date, or is itjava.time.LocalDateor something else?