Java SimpleTimeZone.hasSameRules(TimeZone other) method example

 Posted On  | Pooja Lakkihal 

In this tutorial, You will learn how to check if this zone has the same rules or not . Java SimpleTimeZone.hasSameRules(TimeZone other) method returns true if this zone has the same rules.

Returns true if this zone has the same rules and offset as another zone.

syntax

public boolean hasSameRules(TimeZone other)

Parameter

other - the TimeZone object to be compared with.

Returns

true if the given zone is a SimpleTimeZone and has the same rules and offset as this one.

Java SimpleTimeZone hasSameRules(TimeZone other) example

  • new SimpleTimeZone(100, "INDIA"); It will construct a SimpleTimeZone with the given base time zone.
  • simpleTimeZone1.hasSameRules(simpleTimeZone2); It will check if this zone has the same rules and offset as another zone.
package com.technicalkeeda;

import java.util.SimpleTimeZone;

public class App {

    public static void main(String[] args) {

        SimpleTimeZone simpleTimeZone1 = new SimpleTimeZone(100, "INDIA");
        SimpleTimeZone simpleTimeZone2 = new SimpleTimeZone(100, "INDIA");
        SimpleTimeZone simpleTimeZone3 = new SimpleTimeZone(200, "US");

        boolean samerule1 = simpleTimeZone1.hasSameRules(simpleTimeZone2);
        boolean samerule2 = simpleTimeZone1.hasSameRules(simpleTimeZone3);

        System.out.println("Is simpleTimeZone1 same as simpleTimeZone2 ? " + samerule1);
        System.out.println("Is simpleTimeZone1 same as simpleTimeZone3 ? " + samerule2);

    }
}

output

Is simpleTimeZone1 same as simpleTimeZone2 ? true
Is simpleTimeZone1 same as simpleTimeZone3 ? false


© technicalkeeda.com 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0459 seconds.