Java Tutorials

Java 8 DateTime Classes

      New package called java.time added in java 8 has new Date, Time, DateTime classes i.e LocalDate,LocalTime,LocalDateTime classes respectively. These are an alternative classes for handling Date time related functionality in JDK8. Earlier versions of Java has Date & Calendar classes to deal with Date & Time functionaly.and it has some limitations called epoch time. New Classes has overcome those problems on Dates. And also It supports various calendars systems like Gregorian Calendar, Buddist Calendar, Japanese calendar Systems etc.,.

LocalDate Class

     LocalDate maintains Year,Month,& Day only. It doesnt conatin time functions and TimeZones related information. It has additional functions for Adding,Substracting Dates,Comparing Dates etc., LocalDate uses ISO-8601 calendar system

LocalTime Class

     LocalTime maintains only Time information. Hours,Minutes,Seconds,and Fraction of Seconds. It doesnt contain TimeZone Information.

LocalDateTime Class

     LocalDateTime maintains Date and Time in Sinlge class. It doesnt contain TimeZone Information.

Other Classes in java.time package has

  • Instance
  •    Instance: encapsulates Instance in Time

  • Duration
  •      Duration: encapsulates Length of Time

  • Period
  •      Period:encapsulates Length of Date