import javafx.scene.control.DatePicker;
@FXML<br> private DatePicker datePickerOd;
datePickerOd.setPromptText("dd-mm-yyyy");
datePickerOd.setConverter(new DatePickerConverter());
private class DatePickerConverter extends StringConverter<LocalDate> {
String stringPattern = "dd-MM-yyyy";
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(stringPattern);
public DatePickerConverter() {
}
public DatePickerConverter(String stringPattern) {
this.stringPattern = stringPattern;
this.dateFormatter = DateTimeFormatter.ofPattern(stringPattern);
}
@Override
public String toString(LocalDate object) {
if (object != null) {
return dateFormatter.format(object);
} else {
return "";
}
}
@Override
public LocalDate fromString(String string) {
if (string != null && !string.isEmpty()) {
return LocalDate.parse(string, dateFormatter);
} else {
return null;
}
}
}