java.time.format.DateTimeParseException: Text '2016-2-2' could not be parsed at index 5

Viewed 13080

I am trying to make an instance of LocalDate from import java.time.LocalDate; and i follow this

and here is my code:

     LocalDate sd=  LocalDate.parse("2016-2-2");

and i faced with the error:

java.time.format.DateTimeParseException: Text '2016-2-2' could not be parsed at index 5
    at java.time.format.DateTimeFormatter.parseResolved0(Unknown Source)

In another try to make an instance of LocalDate, i tried

LocalDate ed=  new LocalDate("2016-2-4");

but it again complains:

The constructor LocalDate(String) is undefined
2 Answers
Related