Compare two Java Date objects using compareTo method example
import java.util.Date; public class Main { public static void main(String[] args) { Date d1 = new Date(); Date d2 = new Date(); System.out.println("First Date : " + d1); System.out.println("Second Date : " + d2); int results = d1.compareTo(d2); if (results > 0) { System.out.println("after"); } else if (results < 0) { System.out.println("before"); } else { System.out.println("Both dates are equal"); } } }