Java Convert ZonedDateTime to ZoneId

Tags: Java ZonedDateTime Java ZoneId Java 8

In this Java core tutorial we learn how to convert a java.time.ZonedDateTime object into java.time.ZoneId object in Java programming language.

How to convert ZonedDateTime to ZoneId in Java

In Java, to convert a ZonedDateTime object to ZoneId object we can use the ZonedDateTime.getZone() method as the Java program below.

ConvertZonedDateTimeToZoneIdExample1.java

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

public class ConvertZonedDateTimeToZoneIdExample1 {
    public static void main(String... args) {
        ZonedDateTime zonedDateTime = ZonedDateTime.now();

        ZoneId zoneId = zonedDateTime.getZone();

        System.out.println("ZonedDateTime: " + zonedDateTime);
        System.out.println("ZoneId: " + zoneId);
    }
}
The output as below.
ZonedDateTime: 2022-05-07T00:19:04.423971600+07:00[Asia/Bangkok]
ZoneId: Asia/Bangkok

Happy Coding 😊

Java Convert ZonedDateTime to Instant

Java Convert ZonedDateTime to Date

Java Convert ZonedDateTime to Calendar

Java Convert ZonedDateTime to LocalDateTime

Java Convert ZonedDateTime to OffsetDateTime

Java Convert ZonedDateTime to LocalTime

Java Convert ZonedDateTime to LocalDate

Java Convert ZonedDateTime to ZoneOffset

Java Convert ZonedDateTime to Epoch Seconds

Java Convert ZonedDateTime to String

Java Convert String to ZonedDateTime