Home »
Java programming language
Java SimpleTimeZone hasSameRules() Method with Example
SimpleTimeZone Class hasSameRules() method: Here, we are going to learn about the hasSameRules() method of SimpleTimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 12, 2020
SimpleTimeZone Class hasSameRules() method
- hasSameRules() method is available in java.util package.
- hasSameRules() method is used to check whether this SimpleTimeZone and the given TimeZone (tz) has the same rules and offset or not.
- hasSameRules() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
- hasSameRules() method does not throw an exception at the time of checking rules and offset.
Syntax:
public boolean hasSameRules(TimeZone tz);
Parameter(s):
- TimeZone tz – represents theTimeZone object to be compared with this SimpleTimeZone.
Return value:
The return type of the method is boolean, it returns true when this object and the given object has same rules and offset otherwise it returns false.
Example:
// Java program to demonstrate the example
// of boolean hasSameRules(TimeZone tz) method
// of SimpleTimeZone
import java.util.*;
public class HasSameRulesOfSimpleTimeZone {
public static void main(String args[]) {
// Instantiates SimpleTimeZone object
SimpleTimeZone s_tz1 = new SimpleTimeZone(360, "FRANCE");
SimpleTimeZone s_tz2 = new SimpleTimeZone(760, "JAPAN");
// By using hasSameRules() method
// is to check whether the rules of
// both objects are same or not
boolean status = s_tz1.hasSameRules(s_tz2);
// Display status
System.out.print("s_tz1.hasSameRules(s_tz2): ");
System.out.println(status);
}
}
Output
s_tz1.hasSameRules(s_tz2): false