3

This question may be silly but I can't figure out why.

I want to list all of GMT offsets. There are only 24 hours a day so I thought there are only 24 GMT+/-.

But I found out there are 26 GMT+/- (GMT, GMT-1 to GMT-12, GMT+1 -> GMT+14)

Please see this test https://www.mkyong.com/java/java-display-list-of-timezone-with-gmt/

Can some one tell me why? Thanks!

LHA
  • 9,398
  • 8
  • 46
  • 85
  • maybe https://en.wikipedia.org/wiki/UTC%2B14:00 – ZhongYu Feb 15 '17 at 21:43
  • 1
    This isn't a programming question. I'm actually not certain, but I would guess Time Zones are a geography topic. – puhlen Feb 15 '17 at 21:46
  • 1
    There are actually even more than that, and it's explained in the documentation: https://docs.oracle.com/javase/8/docs/api/java/time/ZoneOffset.html. The reason, basically, is that the offset that a region/country uses is a political decision. – JB Nizet Feb 15 '17 at 21:47
  • 1
    politicians love to mess around with clocks. – ZhongYu Feb 15 '17 at 21:48
  • @puhlen Time zones are a common and critical issue for programming apps. How we represent and process time zones in software is very much a practical issue for programmers. This issue directly affects multiple classes bundled with Java. While I understand your concern about going off topic, I would consider this issue on-topic for Stack Overflow just as I would questions around Unicode or floating-point. – Basil Bourque Feb 15 '17 at 22:14
  • I'm voting to close this question as off-topic because it is not asking about programing. It is asking about how timezones work. – flakes Feb 15 '17 at 23:10
  • @BasilBourque Timezones are important in programming, but this question isn't about how to use timezones or how timezones work, but about why certain timezones exist in the world which is not remotely a programing question, but a geopolitical one. – puhlen Feb 15 '17 at 23:32
  • Not about programming… and yet both answers present built-in Java classes to address the issue … hmmmm… – Basil Bourque Feb 16 '17 at 00:47

2 Answers2

4

There's actually significantly more offsets than what you had originally thought - from that Wikipedia article, there are about 40 of them.

The reason for this is multiple:

  • Different countries may choose to offset their clocks to either be hours and hours behind Grenwich, or hours and hours ahead of Grenwich.
  • Different countries permit offsets which aren't by the hour; Newfoundland in parts for instance has an offset of a half-hour. Nepal has an offset of 45 minutes.
  • Governments may arbitrarily decide to change their timezones at will, which means that the number of offsets that exist is always in flux. Case in point: Samoa jumped across the International Date Line.

Armed with this knowledge, you should take some solace in knowing that Java's ZoneOffset supports an offset range of +18:00 to -18:00, and ZoneOffset.of accepts a String parameter. If you really wanted to enumerate all of the known possible timezones, you could use some string manipulation and generate the possible timezones that way (and keep track of the ones that are valid, or don't throw a DateTimeException), but I leave this as an exercise for the reader.

Makoto
  • 104,088
  • 27
  • 192
  • 230
0

The java.time classes have planned for the possibility of an even wider spread of time zones as zones are frequently re-defined.

To quote the java.time.ZoneOffset class documentation:

In 2008, time-zone offsets around the world extended from -12:00 to +14:00. To prevent any problems with that range being extended, yet still provide validation, the range of offsets is restricted to -18:00 to 18:00 inclusive.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
mjhouseman
  • 164
  • 2
  • 18