Friday, September 5, 2025
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

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS