SimpleTimeZone hasSameRules() method in Java with Examples

The hasSameRules() method of SimpleTimeZone class returns ‘true’ if this zone has the same rules and offset as another zone.

Syntax:

public boolean hasSameRules(TimeZone other)

Parameters: The function accepts a single parameter other which is the TimeZone object to be compared with.



Return Value: It returns ‘true’ if the given zone is a SimpleTimeZone and has the same rules and offset as this one.

Exception: The function does not throws any exceptions.

Program below demonstrates the above mentioned function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

Hash same rule = false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

Hash same rule = true


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

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.