Java Data Type How to - Create date from year, month and day of month








Question

We would like to know how to create date from year, month and day of month.

Answer

import java.time.LocalDate;
import java.time.Month;
/* ww w .ja v  a 2s  . co  m*/
public class Main {

  public static void main(String[] args) {
    int year = 2014;
    Month month = Month.JULY;
    int dayOfMonth = 14;
    LocalDate jugILThisYear = LocalDate.of(year, month, dayOfMonth);

    System.out.println(jugILThisYear);
  }
}

The code above generates the following result.