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

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

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

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

句法:

public boolean equals(Object other)

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

返回值:如果两个对象相等,则此方法返回 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
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans1
            = ZoneOffsetTransitionRule
                  .of(
                      Month.JANUARY, 12,
                      DayOfWeek.SUNDAY,
                      LocalTime.of(03, 24, 45),
                      false,
                      ZoneOffsetTransitionRule
                          .TimeDefinition
                          .STANDARD,
                      ZoneOffset.ofTotalSeconds(8),
                      ZoneOffset.ofTotalSeconds(10),
                      ZoneOffset.ofTotalSeconds(12));
  
        // creating and initializing
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans2
            = ZoneOffsetTransitionRule.of(
                Month.JANUARY, 12,
                DayOfWeek.SUNDAY,
                LocalTime.of(03, 24, 45),
                false,
                ZoneOffsetTransitionRule
                    .TimeDefinition
                    .STANDARD,
                ZoneOffset.ofTotalSeconds(8),
                ZoneOffset.ofTotalSeconds(10),
                ZoneOffset.ofTotalSeconds(12));
  
        // 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
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans1
            = ZoneOffsetTransitionRule
                  .of(
                      Month.JANUARY, 12,
                      DayOfWeek.SUNDAY,
                      LocalTime.of(03, 24, 45),
                      false,
                      ZoneOffsetTransitionRule
                          .TimeDefinition
                          .STANDARD,
                      ZoneOffset.ofTotalSeconds(8),
                      ZoneOffset.ofTotalSeconds(10),
                      ZoneOffset.ofTotalSeconds(12));
  
        // creating and initializing
        // ZoneOffsetTransitionRule Object
        ZoneOffsetTransitionRule zonetrans2
            = ZoneOffsetTransitionRule
                  .of(
                      Month.JANUARY, 16,
                      DayOfWeek.SUNDAY,
                      LocalTime.of(03, 24, 45),
                      false,
                      ZoneOffsetTransitionRule
                          .TimeDefinition
                          .STANDARD,
                      ZoneOffset
                          .ofTotalSeconds(8),
                      ZoneOffset
                          .ofTotalSeconds(10),
                      ZoneOffset
                          .ofTotalSeconds(12));
  
        // 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/ZoneOffsetTransitionRule.html#equals-java.lang.Object-