alexcuesta

My tech blog

Date and Time on Java 8

leave a comment »

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.

https://skillsmatter.com/skillscasts/6232-date-and-time-in-java-se-8

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.

Written by alexcuesta

March 14, 2015 at 11:54 am

Posted in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: