Java ChronoZonedDateTime isEqual()方法及实例
Java中ChronoZonedDateTime接口的 isEqual() 方法用于检查作为参数传递的日期是否与这个ChronoZonedDateTime实例相等。它返回一个显示相同的布尔值。
语法
default boolean isEqual(ChronoZonedDateTime otherDate)
参数。这个方法接受一个参数otherDate,它指定了要与这个ChronoZonedDateTime比较的其他日期时间。它不应该是空的。
返回: 该函数返回布尔值,显示该日期时间是否等于指定日期时间。
以下程序说明了ChronoZonedDateTime.isEqual()方法。
程序1 :
// Program to illustrate the isEqual() method import java.util.*;import java.time.*;import java.time.chrono.*; public class GfG { public static void main(String[] args) { // Parses the date ChronoZonedDateTime dt1 = ZonedDateTime.parse( "2018-12-06T19:21:12.123+05:30[Asia/Calcutta]"); // Prints the date System.out.println(dt1); // Parses the date ChronoZonedDateTime dt2 = ZonedDateTime.parse( "2018-12-06T19:21:12.123+05:30[Asia/Calcutta]"); // Prints the date System.out.println(dt2); // Compares both dates System.out.println(dt1.isEqual(dt2)); }}
输出:
2018-12-06T19:21:12.123+05:30[Asia/Calcutta]2018-12-06T19:21:12.123+05:30[Asia/Calcutta]true
程序2
// Program to illustrate the isEqual() method import java.util.*;import java.time.*;import java.time.chrono.*; public class GfG { public static void main(String[] args) { // Parses the date ChronoZonedDateTime dt1 = ZonedDateTime.parse( "2018-10-06T19:21:12.123+05:30[Asia/Calcutta]"); // Prints the date System.out.println(dt1); // Parses the date ChronoZonedDateTime dt2 = ZonedDateTime.parse( "2018-12-06T19:21:12.123+05:30[Asia/Calcutta]"); // Prints the date System.out.println(dt2); // Compares both dates System.out.println(dt1.isEqual(dt2)); }}输出:
2018-10-06T19:21:12.123+05:30[Asia/Calcutta]2018-12-06T19:21:12.123+05:30[Asia/Calcutta]false
参考资料: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoZonedDateTime.html#isEqual-java.time.chrono.ChronoZonedDateTime-
