I used this method to setting DatePicker
value:
public static final LocalDate LOCAL_DATE (String dateString){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
LocalDate localDate = LocalDate.parse(dateString, formatter);
return localDate;
}
try {
datePicker.setValue(LOCAL_DATE("2016-05-01");
} catch (NullPointerException e) {}
But sometimes throw an exception:
java.time.format.DateTimeParseException: Text '' could not be parsed at index 0
So what's the wrong here?
You specify a format for parsing the date of dd-MM-yyyy
:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
but then you provide the date in a format that doesn't match that:
datePicker.setValue(LOCAL_DATE("2016-05-01"));
Obviously, "2016-05-01"
is not in the format "dd-MM-yyyy"
.
Try
datePicker.setValue(LOCAL_DATE("01-05-2016"));
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