I'm new to java.time package. I have a LocalDate 2015-12-10. I need to convert this to ZonedDateTime. Time should be 00:00:00 and Zone is ZoneOffset.UTC.
After conversion, ZonedDateTime should be 2015-12-10T00:00:00+02:00.
I'm storing the LocalDate in a variable called startDate.
I tried:
ZonedDateTime.ofInstant(Instant.from(startDate), ZoneOffset.UTC)
but get the error
java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: 2015-12-10 of type java.time.LocalDate]
I also tried:
startDate.atStartOfDay().atZone(ZoneOffset.UTC)
This gives unexpected results.
I looked at the API and tried a few other methods, but no luck so far.
Is there any other way to convert LocalDate to ZonedDateTime?
OffsetDateTime offsetDateTimeDateTime = date.atStartOfDay().atOffset(ZoneOffset.ofHours(2));
– Trevino