Java Convert LocalDate to ZonedDateTime

Tags: Java LocalDate Java ZonedDateTime Java 8

In Java ZonedDateTime is a date-time data type with a time-zone in the ISO-8601 calendar system, such as 2022-07-11T10:15:30+01:00 Europe/Paris. In this Java core tutorial we learn how to convert a java.time.LocalDate object to a java.time.ZondedDateTime object in Java programming language.

How to convert LocalDate to ZonedDateTime

In Java with a given LocalDate object we can use LocalDate.atStartOfDay() method with a specified ZoneId to convert LocalDate to ZonedDateTime.

In the following Java program we convert a LocalDate to ZonedDateTime with the default system time zone.

ConvertLocalDateToZonedDateTimeExample1.java

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ConvertLocalDateToZonedDateTimeExample1 {
    public static void main(String... args) {
        LocalDate localDate = LocalDate.of(2022, 7, 11);

        ZoneId zoneId = ZoneId.systemDefault();
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(zoneId);

        System.out.println("LocalDate: " + localDate);
        System.out.println("ZonedDateTime: " + zonedDateTime);
    }
}
The output as below.
LocalDate: 2022-07-11
ZonedDateTime: 2022-07-11T00:00+07:00[Asia/Bangkok]

We can convert LocalDate to ZonedDateTime at a specified time zone, using the ZoneId.of() method to get instance of ZoneId as the following Java program.

ConvertLocalDateToZonedDateTimeExample2.java

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ConvertLocalDateToZonedDateTimeExample2 {
    public static void main(String... args) {
        LocalDate localDate = LocalDate.of(2022, 7, 11);

        ZoneId sydneyZoneId = ZoneId.of("Australia/Sydney");
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(sydneyZoneId);

        System.out.println("LocalDate: " + localDate);
        System.out.println("ZonedDateTime: " + zonedDateTime);
    }
}
The output as below.
LocalDate: 2022-07-11
ZonedDateTime: 2022-07-11T00:00+10:00[Australia/Sydney]

Happy Coding 😊

Java LocalDate by Examples

Java Convert LocalDate to String

Java Convert LocalDate to LocalDateTime

Java Convert LocalDate to OffsetDateTime

Java Convert LocalDate to Epoch Day

Java Convert LocalDate to Date

Java Convert LocalDate to Calendar

Java Convert Date to LocalDate

Java Convert Calendar to LocalDate

Java ZonedDateTime.now() method with Examples

Java ZonedDateTime.of() Method with Examples

Java ZonedDateTime.ofLocal() Method with Examples

Java Convert Epoch Day to LocalDate