Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Java have support for time zone offsets with seconds precision?

Tags:

java

java-time

On Wikipedia time zone offsets are explained as the difference in hours and minutes from standard UTC time. However, DateTimeFormatter supports zone-offset pattern XXXXX, which "outputs the hour and minute and optional second, with a colon, such as '+01:30:15'."

Are offsets like +01:30:15 ISO valid? If not, based on which standard does Java define such offsets?

like image 579
Michal Kordas Avatar asked Apr 23 '19 12:04

Michal Kordas


People also ask

What is offset in timezone in Java?

The OffsetTime class, in effect, combines the LocalTime class with the ZoneOffset class. It is used to represent time (hour, minute, second, nanosecond) with an offset from Greenwich/UTC time (+/-hours:minutes, such as +06:00 or -08:00).

How timezone offset works?

What is a "zone offset"? A zone offset is the difference in hours and minutes between a particular time zone and UTC. In ISO 8601, the particular zone offset can be indicated in a date or time value. The zone offset can be Z for UTC or it can be a value "+" or "-" from UTC.

Does Java date have time zone?

Be aware that java. util. Date objects do not contain any timezone information by themselves - you cannot set the timezone on a Date object. The only thing that a Date object contains is a number of milliseconds since the "epoch" - 1 January 1970, 00:00:00 UTC.

Does timezone offset change?

Breaking Down the Difference An offset is the number of hours or minutes a certain time zone is ahead of or behind GMT**. A time zone's offset can change throughout the year because of Daylight Saving Time. Sometimes laws change a time zone's offset or daylight savings pattern.


1 Answers

It's not supported by ISO-8601, but it is a valid offset as recorded in the IANA time zone database.

Sub-minute offsets are common in the data for the late 19th and early 20th century, before time zones were properly standardized. For example, Europe/Paris had an offset of +00:09:21 until 1911 (according to the IANA database).

The latest occurrence I can find for this is Africa/Monrovia which had a sub-minute offset until 1972!

like image 197
Jon Skeet Avatar answered Oct 20 '22 01:10

Jon Skeet