📌  相关文章
📜  Java中的 ZoneOffsetTransition equals() 方法及示例

📅  最后修改于: 2022-05-13 01:54:52.427000             🧑  作者: Mango

Java中的 ZoneOffsetTransition equals() 方法及示例

Java.time.zone.ZoneOffsetTransition类的equals()方法用于比较 ZoneOffsetTransition 类型的两个对象。

句法:

public boolean equals(Object other)

参数:该方法以其他zoneoffsetTransition的对象为参数。

返回值:如果两个对象相等,则此方法返回 true,否则返回 false。

以下是说明equals()方法的示例:

示例 1:

// Java program to demonstrate
// equals() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
  
public class GFG {
    public static void main(String[] argv)
    {
  
        // creating and initializing
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                1999, 04, 25, 03,
                24, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans2
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // comparing both object using
        // equals() method
        boolean status
            = zonetrans1.equals(zonetrans2);
  
        // display the result
        if (status)
            System.out.println(
                "zonetrans1 is equal to zonetrans2");
        else
            System.out.println(
                "zonetrans1 is not equal to zonetrans2");
    }
}
输出:
zonetrans1 is equal to zonetrans2

示例 2:

// Java program to demonstrate
// equals() method
  
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
  
public class GFG {
    public static void main(String[] argv)
    {
  
        // creating and initializing
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                1999, 04, 25,
                03, 24, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans2
            = ZoneOffsetTransition
                  .of(LocalDateTime.of(
                          1999, 04, 25, 03,
                          24, 48, 0),
                      off1, off2);
  
        // comparing both object using
        // equals() method
        boolean status
            = zonetrans1.equals(zonetrans2);
  
        // display the result
        if (status)
            System.out.println(
                "zonetrans1 is equal to zonetrans2");
        else
            System.out.println(
                "zonetrans1 is not equal to zonetrans2");
    }
}
输出:
zonetrans1 is not equal to zonetrans2

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/zone/ZoneOffsetTransition.html#equals-java.lang.Object-