Create LocalDate Object from Integers

Use LocalDate#of(int, int, int) method that takes year, month and dayOfMonth.


In addition to Rohit's answer you can use this code to get Localdate from String

    String str = "2015-03-15";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDate dateTime = LocalDate.parse(str, formatter);
    System.out.println(dateTime);

You can create LocalDate like this, using ints

      LocalDate inputDate = LocalDate.of(year,month,dayOfMonth);

and to create LocalDate from String you can use

      String date = "04/04/2004";
      inputDate = LocalDate.parse(date,
                      DateTimeFormat.forPattern("dd/MM/yyyy"));

You can use other formats too but you have to change String in forPattern(...)

Tags:

Java

Date

Java 8