A Concise Overview of Java’s Instant, LocalDateTime, ZonedDateTime and When to Use Which

Home » Blog » Software » A Concise Overview of Java’s Instant, LocalDateTime, ZonedDateTime and When to Use Which

The authoritative answer to a question on Stack Overflow on the difference between Instant and LocalDateTime covers various classes from the Java 8 Date/Time API and how those are actually meant to be used.

Names such as LocalDateTime can be misleading in that they suggest a specific locale or locality rather than any locality (as that name is intended). This, in turn, can give rise to problems with inaccurate date and time values if timezones or even just daylight saving time have to be taken into account. Converting existing date and time values for an existing application later on can be real hassle, which is why it’s important to get this right from the get-go.

The answer on Stack Overflow also contains a short comparison between the current Java date & time API (i.e. Java 8 and above) and what’s considered the legacy date & time API (that is, everything used until Java 1.7).

These aspects make this answer a valuable resource on Java date and time classes and the concepts and ideas behind them, as well as some of the potential pitfalls involved.

About the author: Bjoern
Independent IT consultant, entrepreneur

Leave a Comment