Java 8 Date and Time API Enhancements

Enhancement to Date/Time APIs

1. Immutable and Thread Safe — java.util.Date and java.util.Calendar APIs are not thread safe and lead to potential concurrency issues, adding additional headaches to handle thread safety. Date and Time APIs in Java 8 are immutable and therefore thread safe.

Immutable Class Concept

As new Date and Time API’S are immutable, let’s dig into the points that make a class immutable:

LocalDate, LocalTime and LocalDateTime Core APIs

LocalDate — Local date in ISO format (yyyy-MM-dd) without time.

Period and Duration Core Classes

Period — Quantity of days in terms of year, month, etc.

ZonedDateTime Core API

Java 8 provides ZonedDateTime to deal with time zone specific date and time. The ZoneId is an identifier used to represent different zones.

Compatibility with Date and Calendar

The toInstant() method converts existing Date and Calendar instances into new Date Time API object.

Joda-Time Library

In fact, Java 8 Date Time APIs has been led jointly by the author of Joda-Time library (Stephen Colebourne) and Oracle. This library provides pretty much all capabilities that are supported in the Java 8 Date Time project.

Full Stack Developer || Technical Writer || Open source contributer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store