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

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

Java中的 SimpleTimeZone hasSameRules() 方法及示例

如果此区域与另一个区域具有相同的规则和偏移量,则SimpleTimeZone 类hasSameRules()方法返回“true”。

句法:

public boolean hasSameRules(TimeZone other)

参数:该函数接受一个参数other ,它是要与之比较的 TimeZone 对象。

返回值:如果给定区域是 SimpleTimeZone 并且具有与此相同的规则和偏移量,则返回“true”

异常:该函数不抛出任何异常。

下面的程序演示了上述函数:

方案一:

// program to demonstrate the
// function java.util.SimpleTimeZone.hasSameRules()
  
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create first simple time zone object
        SimpleTimeZone obj1
            = new SimpleTimeZone(720, "US");
  
        // create second simple time zone object
        SimpleTimeZone obj2
            = new SimpleTimeZone(800, "GMT");
  
        // check rules for both objects and print the result
        System.out.println("Hash same rule = "
                           + obj1.hasSameRules(obj2));
    }
}
输出:
Hash same rule = false

方案二:

// program to demonstrate the
// function java.util.SimpleTimeZone.hasSameRules()
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create first simple time zone object
        SimpleTimeZone obj1
            = new SimpleTimeZone(720, "US");
  
        // create second simple time zone object
        SimpleTimeZone obj2
            = new SimpleTimeZone(720, "GMT");
  
        // check rules for both objects and print the result
        System.out.println("Hash same rule = "
                           + obj1.hasSameRules(obj2));
    }
}
输出:
Hash same rule = true