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

Leider ist der Eintrag nur auf English verfügbar.

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

Falls du auf diesen Beitrag mit einem Artikel auf deiner eigenen Webseite geantwortet hast, kannst du hier die URL deines Beitrags eingeben. Dabei sollte es sich um die Permalink-URL handeln. Deine Antwort wird dann (möglicherweise nach der Moderation) auf dieser Seite angezeigt. Falls du deine Antwort aktualisieren oder entfernen möchtest, aktualisiere oder lösche deinen Beitrag auf deiner eigenen Webseite und gib die URL des Beitrags erneut ein. (Erfahre mehr über Webmentions.)