How to convert from Instant to LocalDate

JL Gradley picture JL Gradley · Sep 10, 2018 · Viewed 49.7k times · Source

I have an Instant coming from a source that should, according to the spec, be a LocalDate, but don't see any methods in LocalDate for the conversion. What is the best way to do this?

Answer

Rob C picture Rob C · Sep 10, 2018

LocalDate.ofInstant(...); I believe was added in Java 9.

LocalDateTime has that method in Java 8.

yourInstant.atZone(yourZoneId).toLocalDate(); Will work with earlier versions for LocalDate...