The java.util.GregorianCalendar.equals() method is an in-built function in Java which checks for equality between this GregorianCalendar instance and the Object passed as parameter to the function. It returns true only if the specified Object is a GregorianCalendar object with same time value (millisecond offset from the Epoch) as this GregorianCalendar instance.
public boolean equals(Object obj)
Parameters: The function accepts a single mandatory parameter obj which is to be compared with this GregorianCalendar instance.
Return Values: This method returns true only when the specified Object is a GregorianCalendar object and has the same time value (millisecond offset from the Epoch) as this instance and returns false otherwise.
Input : c1 = Mon Jul 23 23:46:14 UTC 2018, c2 = Mon Jul 23 23:46:14 UTC 2018 Output : true Input : c1 = Mon Jul 23 23:46:14 UTC 2018, c2 = Sun Jul 24 00:02:52 UTC 2022 Output : false
Below programs illustrate the java.util.GregorianCalendar.equals() function:
Current Date and Time : Fri Jul 27 12:05:05 UTC 2018 Both calendars are equal:true Modified Date and Time : Sun Oct 27 12:05:05 UTC 2019 Both calendars are equal:false
Current Date and Time : Fri Jul 27 12:05:08 UTC 2018 Both calendars are equal:true Both calendars are equal:false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.