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
相關用法
- Java LocalDate isEqual()用法及代碼示例
- Java MessageDigest isEqual()用法及代碼示例
- Java LocalDateTime isEqual()用法及代碼示例
- Java OffsetTime isEqual()用法及代碼示例
- Java ChronoLocalDate isEqual()用法及代碼示例
- Java ChronoLocalDateTime isEqual()用法及代碼示例
- Java OffsetDateTime isEqual()用法及代碼示例
- Java ChronoZonedDateTime from()用法及代碼示例
- Java ChronoZonedDateTime get()用法及代碼示例
- Java ChronoZonedDateTime until()用法及代碼示例
- Java ChronoZonedDateTime compareTo()用法及代碼示例
- Java ChronoZonedDateTime withEarlierOffsetAtOverlap()用法及代碼示例
- Java ChronoZonedDateTime with(TemporalAdjuster)用法及代碼示例
- Java ChronoZonedDateTime getZone()用法及代碼示例
- Java ChronoZonedDateTime plus(TemporalAmount)用法及代碼示例
注:本文由純淨天空篩選整理自ShubhamMaurya3大神的英文原創作品 ChronoZonedDateTime isEqual() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。