localdate cannot be converted date

2.1k Views Asked by At

FXML on datepicker

@FXML private DatePicker dp_detay_cal;

pojo.setFirstDate(dp_detay_cal.getValue());

error: localdate cannot be converted date

how to converted

1

There are 1 best solutions below

1
On BEST ANSWER

The preferred solution would be to use a LocalDate as the type for your firstDate property in your pojo class.

A java.util.Date includes more information that a LocalDate; it includes a time (of day) and a time zone. So you need to include some values for those before you can convert to a Date.

If, for some reason, you can't change the pojo class, try

LocalDateTime localDateTime = dp_detay_cal.getValue().atStartOfDay();
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
Instant instant = Instant.from(zonedDateTime);
pojo.setFirstDate(Date.from(instant));