Often, we would want to compare date and time instances with others to check if they are before, after, or the same as that of the other. To achieve this, JDK provides isBefore(), isAfter(), and isEqual() methods in the java.time.LocalDate, java.time.LocalDateTime, and java.time.ZonedDateTime classes. In this recipe, we will look at using these methods to compare date and time instances.
How to compare date and time
Getting ready
You will need a JDK installation that has the new Date/Time APIs and supports JShell.
How to do it...
- Let's try out comparing two java...