Friday, November 22, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments