Scenario 1
val date1 = LocalDate.parse("2017-02-07")
val date2 =LocalDate.parse("2017-02-01")
date1.isAfter(date2)
Output
true
Scenerio 2
val date1 = LocalDate.parse("2017-02-07")
val date2 =LocalDate.parse("2017-02-07")
date1.isAfter(date2)
Output
false
I want to return true
when date is > = "2017-02-07"
For comparing the two dates, we have used the compareTo() method. If both dates are equal it prints Both dates are equal. If date1 is greater than date2, it prints Date 1 comes after Date 2. If date1 is smaller than date2, it prints Date 1 comes after Date 2.
equals(): Syntax: date1. equals(date2) Return Type: Boolean This function returns true strictly if date1 and date2 are equal, else it returns false. The equals() method of Date class checks for equality by comparing the number of milliseconds elapsed since 1st January 1970, 00:00:00 GTM.
The date object allows us to perform comparisons using the > , < , = , or >= comparison operators, but not the equality comparison operators like == , != , === , and !== (unless we attach date methods to the date Object).
Use an OR. afaik, there is no method in the API to do that in a single operation
date1.isAfter(date2) || date1.isEqual(date2)
Another option:
date1.compareTo(date2) >=0
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