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!
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With