Java8 Lambda Date & Time


A long-standing bugbear of Java developers has been the inadequate support for the date and time use cases of ordinary developers.

For example, the existing classes (such as java.util.Date and SimpleDateFormatter) aren’t thread-safe, leading to potential concurrency issues for users—not something the average developer would expect to deal with when writing date-handling code.

Some of the date and time classes also exhibit quite poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0—not very intuitive.

These issues, and several others, have led to the popularity of third-party date and time libraries, such as Joda-Time.

In order to address these problems and provide better support in the JDK core, a new date and time API, which is free of these problems, has been designed for Java SE 8.

The project has been led jointly by the author of Joda-Time (Stephen Colebourne) and Oracle, under JSR 310, and will appear in the new Java SE 8 package java.time.

LocalDate - a date without time. It can be used to store birthday, anniversary, etc.
LocalTime - represents time without a date.
LocalDateTime - is used to combine date and time, but still without any offset or time-zone.
OffsetTime - It represents a time with time-zone.
OffsetDateTime - It represents a timestamp with time-zone.



Creating Program in Java8(Lambda) to show Date & Time


Follow the below steps to write program with java8(Lambda).
Step-1

Create a package com.javat.date under sources package. Then create the Java class Java8DateDemo.java. Once you are ready then write the code as shown below.




Output

Java8DateDemo.java



Download example and run it on Netbeans IDE