Date and Time API

(Joda-Time API)

Until java 1.7 version the classes present in java.util package to handle Date and Time (like Date, Calendar, and Time Zone etc.) are not up to the mark with respect to convenience and performance. To overcome this problem in the 1.8 version oracle people introduced Joda-Time API.

This API is developed by joda.org and available in Java in the form of Java.time package.

Program for to display System Date and time.

Once we get Local Date object we can call the following methods on that object to retrieve Day, Month and Year values separately.

Once we get Local Time object we can call the following methods on that object.

 If we want to represent both Date and Time then we should go for LocalDateTime object.

We can represent a particular Date and Time by using LocalDateTime object as follows.
Example:

Example:

To Represent Zone:          Zoneld object can be used to represent Zone.

We can create Zoneld for a particular zone as follows

Example:
Zoneld la = Zoneld.of (“India/Andra’);
ZonedDateTime zt = ZonedDateTime.now(la); system.out.println(zt);

Period Object:Period object can be used to represent quantity of time.

Example:

write a program to check the given year is leap year or not.


Java 8 Features Java 9 Features