Java TimeZone - hasSameRules() Method
The java.util.TimeZone.hasSameRules() method returns true if this zone has the same rule and offset as another zone.
Syntax
public boolean hasSameRules(TimeZone other)
Parameters
other |
Specify the TimeZone object to be compared with. |
Return Value
Returns true if the other zone is not null and is the same as this one, with the possible exception of the ID.
Exception
NA
Example:
In the example below, the java.util.TimeZone.hasSameRules() method is used to check if two time zones have same rules.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating a TimeZone objects TimeZone tz1 = TimeZone.getTimeZone("IST"); TimeZone tz2 = TimeZone.getTimeZone("IST"); TimeZone tz3 = TimeZone.getTimeZone("GMT"); //checking if tz1 and tz2 have same rules System.out.print("tz1 and tz2 have same rule: "); System.out.println(tz1.hasSameRules(tz2)); //checking if tz1 and tz3 have same rules System.out.print("tz1 and tz3 have same rule: "); System.out.println(tz1.hasSameRules(tz3)); } }
The output of the above code will be:
tz1 and tz2 have same rule: true tz1 and tz3 have same rule: false
❮ Java.util - TimeZone