isequal
isEqual() method is available in java.time package.
isEqual()方法在java.time包中可用。
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()方法用于检查此日期时间对象值是否等于给定的日期时间对象(l_datetime)值。
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()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
isEqual() method does not throw an exception at the time of checking the status.
isEqual()方法在检查状态时不会引发异常。
Syntax:
句法:
public boolean isEqual(ChronoLocalDateTime l_datetime);
Parameter(s):
参数:
ChronoLocalDateTime l_datetime – represents the ChronoLocalDateTime object to be compared with this LocalDateTime for equality.
ChronoLocalDateTime l_datetime –表示要与该LocalDateTime比较的ChronoLocalDateTime对象是否相等。
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.
此方法的返回类型为boolean ,当此日期时间对象的值等于给定的日期时间对象值时,它返回true,否则返回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
翻译自: https://www.includehelp.com/java/localdatetime-isequal-method-with-example.aspx
isequal