Java 8, why not a ZonedTime class?

老子叫甜甜 提交于 2019-12-23 07:46:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26538102/java-8-why-not-a-zonedtime-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!