Saturday 7 February 2015

Java8 New API Date Time: Overview

The new API Date Time for java 8 is included in the package java.time.

  • Class LocalDate --> date
  • Class LocalTime --> time
  • Class LocalDateTime --> timestamp

The new date and time classes are thread safe (they are not mutable and can be used in multithread). This is an advantage respect from the previous API (Date and Calendar classes).

Now, let's see some easy examples about how to apply this new DateTime classes.

Examples with dates (LocalDate class)
    • get current date
    • set date methods of/with
    • dayOfWeek, yearMonth, year
    • parsing dates
    • calculations (plus/minus)
    • comparing dates
    • Period class



Examples with time (LocalTime class)
    • LocalTime current time, constants
    • Duration : calculation with times
    • LocalDateTime : obtain timestamp



No comments:

Post a Comment