Date and Time on Java 8
I highly recommend to watch this video about date and time concepts and how they are handled on Java 8. You will understand why dates and times are so difficult to implement. By the way, It is not Joda time, it is inspired by Joda time.
It covers concepts like:
- LocalDate: Local Dates like “10th October 1977” without time taking the Time Zone into account.
- LocalTime: Local Times like “21:33:23” without taking the Time Zone into account. Up to nanoseconds!
- LocalDateTime: A combination of the two above.
- ZonedDateTime: The same but taking Time Zone into account. This topic is very well explained in the video. It talks about how the following concepts complicate things:
- Offset: Madrid is +1h from GMT (Greenwich). There are places where they had +14h! Crazy stuff!
- Political rules which decided to move TimeZone. These rules are stored in the TimeZone Database (TZD)
- ZoneId (Europe/London) to identify a place.
- OffsetDateTime and OffsetTime: Dates and times that take offset into account only but no time zone. Used on HTML and JSON for example.
- Instant, Duration and Period.
- Leap seconds: Our calendar is not precise compared to an atomic clock and UTC has to introduce one second sometimes. This is not handled very well now.