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?
See Question&Answers more detail:osI 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?
See Question&Answers more detail:osLocalDate.ofInstant(...);
arrived in Java 9.
Instant instant = Instant.parse( "2020-01-23T00:00:00Z" );
ZoneId z = ZoneId.of( "America/Edmonton" );
LocalDate ld = LocalDate.ofInstant( instant , z );
See code run live at IdeOne.com.
Notice the date is 22nd rather than 23rd as that time zone uses an offset several hours before UTC.
2020-01-22
ZonedDateTime
has a .toLocalDate()
method in Java 8.
yourInstant.atZone(yourZoneId).toLocalDate();
Will work with earlier versions for LocalDate...