Search code examples
javadatedatetimejava-8datetime-conversion

Java 8 - Convert LocalDate to OffsetDateTime


I like to know if it is possible to convert in Java 8 from LocalDate to OffsetDateTime.

For example assume that I have got this LocalDate:

1992-12-28

Then I would like to have it converted to this OffsetDateTime:

1992-12-28T00:00-03:00

Assume that we know the time zone, for example America/Santiago.


Solution

  • You can try this..

    OffsetDateTime o = OffsetDateTime.of(LocalDate.now(),LocalTime.NOON, ZoneOffset.UTC);
    OffsetDateTime o1 = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.UTC);