Wednesday, February 4, 2026
HomeLanguagesJavaSimpleTimeZone hasSameRules() method in Java with Examples

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:




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


Output:

Hash same rule = false

Program 2:




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


Output:

Hash same rule = true
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32479 POSTS0 COMMENTS
Milvus
125 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11980 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6936 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS