Home »
Java »
Java Reference »
Java LocalDateTime Class
Java LocalDateTime Class | isEqual() Method with Example
LocalDateTime Class isEqual() method: Here, we are going to learn about the isEqual() method of LocalDateTime Class with its syntax and example.
Submitted by Preeti Jain, on June 06, 2020
LocalDateTime Class isEqual() method
- isEqual() method is available in java.time package.
- isEqual() method is used to check whether this date-time object value is equal to the given date-time object (l_datetime) value or not.
- isEqual() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- isEqual() method does not throw an exception at the time of checking the status.
Syntax:
public boolean isEqual(ChronoLocalDateTime l_datetime);
Parameter(s):
- ChronoLocalDateTime l_datetime – represents the ChronoLocalDateTime object to be compared with this LocalDateTime for equality.
Return value:
The return type of this method is boolean, it returns true when this date-time object value is equal to the given date-time object value otherwise it returns false.
Example:
// Java program to demonstrate the example
// of isEqual(ChronoLocalDateTime l_datetime) method
// of LocalDateTime
import java.time.*;
public class IsEqualOfLocalDateTime {
public static void main(String args[]) {
// Instantiates two LocalDateTime
LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10.00");
LocalDateTime da_ti2 = LocalDateTime.now();
// Display da_ti1, da_ti2
System.out.println("LocalDateTime da_ti1 and da_ti2: ");
System.out.println("da_ti1: " + da_ti1);
System.out.println("da_ti2: " + da_ti2);
System.out.println();
// Here, this method checks whether this
// date-time object (da_ti1) is equal to
// the given date-time object (da_ti2) or
// not i.e. here it returns false because
// da_ti1 <> da_ti2
boolean status = da_ti1.isEqual(da_ti2);
// Display status
System.out.print("da_ti1.isEqual(da_ti2): ");
System.out.println(status);
// Here, this method checks whether this
// date-time object (da_ti1) is equal to
// the given date-time object (da_ti1) or
// not i.e. here it returns true because
// da_ti1 == da_ti2
status = da_ti1.isEqual(da_ti1);
// Display status
System.out.print("da_ti1.isEqual(da_ti1): ");
System.out.println(status);
}
}
Output
LocalDateTime da_ti1 and da_ti2:
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-06T21:14:40.640483
da_ti1.isEqual(da_ti2): false
da_ti1.isEqual(da_ti1): true