Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); if(cal1.equals(cal2)) { System.out.println("Calendars represent the same date and time values"); } else { System.out.println("Calendars do not represent the same date and time values"); }
import java.util.GregorianCalendar; GregorianCalendar cal1 = new GregorianCalendar(2021, 3, 10); GregorianCalendar cal2 = new GregorianCalendar(2021, 3, 10); if(cal1.equals(cal2)) { System.out.println("Calendars represent the same date and time values"); } else { System.out.println("Calendars do not represent the same date and time values"); }This example creates two GregorianCalendar objects representing the date April 10, 2021 and checks if they represent the same date and time values using the equals() method. The java.util.Calendar.equals() method is a part of the java.util package library.