Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why GMT and UTC timezones don't have same rules

Tags:

java

timezone

Why does below line print false? i think it should print true.

TimeZone.getTimeZone("UTC+5:30").hasSameRules(TimeZone.getTimeZone("GMT+5:30")
like image 791
Azodious Avatar asked Nov 16 '18 05:11

Azodious


1 Answers

The answer is in the JavaDoc of TimeZone#getTimeZone:

the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00"

Returns: the specified TimeZone, or the GMT zone if the given ID cannot be understood.

And (from the class documentation)

[...] The syntax of a custom time zone ID is:

  CustomID:
     GMT Sign Hours : Minutes
     GMT Sign Hours Minutes
     GMT Sign Hours

The ID "UTC+5:30" is not a valid TimeZone ID (as per the specification of the method/class) and is interpreted as "GMT" zone, which is clearly distinct from the "GMT+5:30" zone.

like image 106
Thomas Kläger Avatar answered Nov 15 '22 16:11

Thomas Kläger