Date date1 = new Date(); Date date2 = new Date(); if (date1.equals(date2)) { System.out.println("The two dates are equal."); } else { System.out.println("The two dates are not equal."); }
Date date1 = new Date(1626998400000L); // July 23, 2021 Date date2 = new Date(1628342400000L); // August 8, 2021 if (date1.equals(date2)) { System.out.println("The two dates are equal."); } else { System.out.println("The two dates are not equal."); }In this example, two Date objects are created with different timestamps representing different days. Since they are not the same moment in time, the equals() method will return false, and the output will be "The two dates are not equal." The java.util.Date class is part of the Java Standard Library, which is included with the Java Development Kit (JDK). Therefore, it does not require any additional package libraries.