Java - Date Time Local Date

Introduction

LocalDate class represents a date without a time or time zone.

Several methods in the class let you convert a LocalDate to other datetime objects and manipulate its fields (year, month, and day) to obtain another LocalDate.

The following snippet of code creates some LocalDate objects:

Demo

import java.time.LocalDate;
import java.time.Month;

public class Main {
  public static void main(String[] args) {
    // Get the current local date
    LocalDate ldt1 = LocalDate.now();

    // Create a local date May 10, 2012
    LocalDate ldt2 = LocalDate.of(2012, Month.MAY, 10);

    // Create a local date, which is 10 days after the epoch date 1970-01-01
    LocalDate ldt3 = LocalDate.ofEpochDay(10); // 1970-01-11
    System.out.println(ldt1);/*from   w ww . ja v a2  s.c o m*/
    System.out.println(ldt2);
    System.out.println(ldt3);
  }
}

Result

Constant

LocalDate class contains two constants, MAX and MIN, that are the maximum and minimum supported LocalDate respectively.

The value for LocalDate.MAX is +999999999-12-31 and LocalDate.MIN is -999999999-01-01.

Related Topics

Quiz