Java TimeZone hasSameRules() Method

The hasSameRules(TimeZone other) is a method of TimeZone class. If the zone has the same rule and offset as another zone, it returns true. If one of the zone is null, it will return false.

Syntax:

Parameters:

other - It is the object of TimeZone to be compared.

Returns:

It returns true if zone and offset have the same rule as the another zone

Example 1

Output:

Comparison result: true

Example 2

Output:

Comparison result:false
TimeZone of Indian/Mahe :sun.util.calendar.ZoneInfo[id="Indian/Mahe",offset=14400000,dstSavings=0,useDaylight=false,
transitions=3,lastRule=null]
TimeZone of Israel:sun.util.calendar.ZoneInfo[id="Indian/Mahe",offset=14400000,dstSavings=0,useDaylight=false,
transitions=3,lastRule=null]

Example 3

Output:

Comparison result: true
TimeZone1 of Indian/Mahe :sun.util.calendar.ZoneInfo[id="Indian/Mahe",offset=14400000,dstSavings=0,useDaylight=false,
transitions=3,lastRule=null]
TimeZone2 of Indian/Mahe:sun.util.calendar.ZoneInfo[id="Indian/Mahe",offset=14400000,dstSavings=0,useDaylight=false,
transitions=3,lastRule=null]