Groovy - Dates & Times equals()



Compares two dates for equality. The result is true if and only if the argument is not null and is a Date object that represents the same point in time, to the millisecond, as this object.

Thus, two Date objects are equal if and only if the getTime method returns the same long value for both.

Syntax

public boolean equals(Object obj)

Parameters

obj - the object to compare with.

Return Value

True if the objects are the same; false otherwise.

Example

Following is an example of the usage of this method −

class Example {
   static void main(String[] args) {
      Date olddate = new Date("05/11/2015");
      Date newdate = new Date("05/11/2015");
      Date latestdate = new Date();
		
      System.out.println(olddate.equals(newdate));
      System.out.println(latestdate.equals(newdate));
   } 
}   

When we run the above program, we will get the following result −

true 
false
groovy_dates_times.htm
Advertisements