after and before in java date
javaTo check if one java.time.LocalDate object is before or after another date, you can use the isBefore() and isAfter() methods.
Here’s an example:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2020, 1, 1);
LocalDate date2 = LocalDate.of(2020, 1, 2);
LocalDate date3 = LocalDate.of(2020, 1, 1);
System.out.println(date1.isBefore(date2)); // true
System.out.println(date1.isBefore(date3)); // false
System.out.println(date1.isAfter(date2)); // false
System.out.println(date1.isAfter(date3)); // false
}
}
You can also use the isEqual() method to check if two dates are equal:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2020, 1, 1);
LocalDate date2 = LocalDate.of(2020, 1, 2);
LocalDate date3 = LocalDate.of(2020, 1, 1);
System.out.println(date1.isEqual(date2)); // false
System.out.println(date1.isEqual(date3)); // true
}
}
You can use these methods with the java.time.LocalDateTime class as well.
Other Article on Tag java
- - after and before in java date
- - am pm java date format
- - apk minecraft java edition
- - as been blocked by CORS policy Response to preflight request doesn't pass access control check It does not have HTTP ok status
- - bubble sort in java
- - Can I compile and run a spring boot jar from inside another spring boot application
- - convert java date to localdate
- - design patterns in java
- - encrypt by java and decrypt by node
- - exception handling in java