How to convert Date into LocalDateTime in Java 8

Date to LocalDateTime

Date date = new Date();
Instant instant = date.toInstant();
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

 

LocalDateTime to Date

LocalDateTime ldt = LocalDateTime.now();
ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
Date date = Date.from(zdt.toInstant());

 

 

You like this content ? Share it with you entourage !

Leave a Reply

Your email address will not be published.