Java Convert LocalDate to OffsetDateTime

Tags: Java LocalDate Java OffsetDateTime Java 8

In this Java core tutorial we learn how to convert a java.time.LocalDate object to a java.time.OffsetDateTime object in Java programming language.

How to convert LocalDate to OffsetDateTime in Java

In Java with a given LocalDate object we can use the LocalDate.atTime() method with a specified OffsetTime value to create a new OffsetDateTime object as the following Java code.

ConvertLocalDateToOffsetDateTimeExample1.java

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;

public class ConvertLocalDateToOffsetDateTimeExample1 {
    public static void main(String... args) {
        LocalDate localDate = LocalDate.now();
        OffsetTime offsetTime = OffsetTime.now();
        OffsetDateTime offsetDateTime = localDate.atTime(offsetTime);

        System.out.println("LocalDate: " + localDate);
        System.out.println("OffsetDateTime: " + offsetDateTime);
    }
}
The output as below.
LocalDate: 2022-04-18
OffsetDateTime: 2022-04-18T01:13:00.674643+07:00

Happy Coding 😊

Java LocalDate by Examples

Java Convert LocalDate to String

Java Convert LocalDate to LocalDateTime

Java Convert LocalDate to Epoch Day

Java Convert LocalDate to ZonedDateTime

Java Convert LocalDate to Date

Java Convert LocalDate to Calendar

Java Convert Date to LocalDate

Java Convert Calendar to LocalDate

Java Convert Epoch Day to LocalDate