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
You need to use a formatter to parse single character day/month fields for java.time.LocalDate
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-d");
LocalDate date = LocalDate.parse("2016-2-2", formatter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With