Juan Lhc
Juan Lhc

Reputation: 327

Java 8, why not a ZonedTime class?

I found that Java 8 doesn't have an equivalent to ZonedDateTime but to work only with Time (a ZonedTime class or something like that). I know they included the OffsetTime class, but it only stores the offset.

Storing time zones along with date and time, instead of just store the offset, helps to deal with daylight savings easier.

I'm not asking you to give me alternatives, I know there are many approaches; I'm just wondering why such class was not included, is it a design issue? or they just found it to be redundant?

Upvotes: 17

Views: 5206

Answers (1)

Meno Hochschild
Meno Hochschild

Reputation: 44071

Introducing a class ZonedTime consisting of LocalTime and a time zone (instead of a simple offset) would be a heavy mistake.

The suggested type does not contain a date. But without a date it will not be possible to evaluate the real timezone offset to map the local time to any sensible global time. For taking into account any daylight saving aspects you must have as well a date and a time.

Upvotes: 17

Related Questions