I use the Java 8 DatePicker (and I like it).
This Class uses java.time.LocalDate
.
Persistence
on the other hand uses (exclusively in MAR 2014) java.util.Date
.
LocalDate2Date
is involved but doable (see below)
but I can't find a way to do Date2LocalDate.
....
entityClassFromDatabase.setDate2b(LocalDate2Date(datepicker.getvalue()));
....
}
private java.util.Date LocalDate2Date(LocalDate localDate) {
[validation code omitted]
ChronoLocalDateTime cldt = localDate.atStartofDay();
Instant instant = cldt.toInstant(ZoneOffset.from(Instant.now().atZone(ZoneId.systemDefault())));
return Date.from.(instant);
}
What I need is something like;
datepicker.setvalue(Date2LocalDate(entityClassFromDatabase.getDate2b());
I have seen answers that suggest new LocalDate(date); and variants, but these do not work;
Latest effort was 'conversion' via java.time.Instant
but although the 'instant' used in LocalDate2Date
prints out identical to the instant used below:
Instant instant = entityClassFromDatabase.getDate2b.toinstant();
LocalDateTime xx = LocalDateTime.from(instant);
throws exception below:
java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: 2014-03-27T23:00:00Z of type java.time.Instant
I'm lost