TimeZone hasSameRules() Method in Java with Examples
The hasSameRules() method of TimeZone class in Java is used to check for equality between two TimeZones. The method returns True if the specified TimeZone has same rule and offset value as the other TimeZone.
Syntax:
public boolean hasSameRules(TimeZone TimeZone_2)
Parameters: The method takes one parameter TimeZone_2 of object type which refers to the TimeZone that is needed to be compared with this TimeZone.
Return Value: The method returns boolean True if both the TimeZone share same rule and offset value with only an exception of IDs else False.
Below program illustrates the working of hasSameRules() Method of TimeZone:
// Java code to illustrate hasSameRules() method import java.util.*; public class TimeZone_Demo { public static void main(String args[]) { // Creating the first TimeZone TimeZone first_time_zone = TimeZone.getDefault(); // Creating the second TimeZone TimeZone sec_time_zone = TimeZone.getDefault(); // Applying hasSameRules() to check for equality System.out.println("The equality holds: " + first_time_zone .hasSameRules(sec_time_zone)); } } |
The equality holds: true
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#hasSameRules()
Recommended Posts:
- SimpleTimeZone hasSameRules() method in Java with Examples
- TimeZone useDaylightTime() method in Java with Examples
- TimeZone getDSTSavings() Method in Java with Examples
- TimeZone setDefault() Method in Java with Examples
- TimeZone setRawOffset() Method in Java with Examples
- TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
- TimeZone getRawOffset() Method in Java with Examples
- TimeZone clone() Method in Java with Examples
- TimeZone getOffset() Method in Java with Examples
- TimeZone getID() Method in Java with Examples
- TimeZone inDaylightTime() method in Java with Examples
- TimeZone getAvailableIDs() Method in Java with Examples
- TimeZone getDefault() Method in Java with Examples
- TimeZone observesDaylightTime() method in Java with Examples
- TimeZone getTimeZone() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

