What is the best way to convert a java.util.Date
object to the new JDK 8/JSR-310 java.time.LocalDate
?
Date input = new Date();
Loca
Date input = new Date();
LocalDateTime conv=LocalDateTime.ofInstant(input.toInstant(), ZoneId.systemDefault());
LocalDate convDate=conv.toLocalDate();
The Date
instance does contain time too along with the date while LocalDate
doesn't. So you can firstly convert it into LocalDateTime
using its method ofInstant()
then if you want it without time then convert the instance into LocalDate
.