Java LocalDate create from 'of' factory method as of(2020, 5, 2)

Description

Java LocalDate create from 'of' factory method as of(2020, 5, 2)

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

public class Main {
  public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2020, 5, 2);
    // Use an of() to build a date 2020-05-22
    System.out.println(ld);/*w w w .j  a  v a 2 s  . com*/

    LocalDate ld1 = LocalDate.of(2020, 5, 2); // 2020-05-02
    LocalDate ld2 = LocalDate.of(2020, Month.JULY, 4); // 2020-07-04
    LocalDate ld3 = LocalDate.ofEpochDay(2002); // 1975-06-26
    LocalDate ld4 = LocalDate.ofYearDay(2020, 40); // 2020-02-09
    System.out.println(ld1);
    System.out.println(ld2);
    System.out.println(ld3);
    System.out.println(ld4);

  }
}



PreviousNext

Related