Java Convert Instant to OffsetDateTime

Tags: Java Instant Java OffsetDateTime Java 8

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

How to convert Instant to OffsetDateTime in Java

In Java, with a given Instant object we can use the OffsetDateTime.ofInstant(Instant instant, ZoneId zone) static method to convert it to a OffsetDateTime object with system time zone as the following example Java code.

ConvertInstantToOffsetDateTimeExample1.java

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;

public class ConvertInstantToOffsetDateTimeExample1 {
    public static void main(String... args) {
        Instant instant = Instant.now();

        OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(instant, ZoneId.systemDefault());

        System.out.println("Instant: " + instant);
        System.out.println("OffsetDateTime: " + offsetDateTime);
    }
}
The output as below.
Instant: 2022-05-17T16:38:32.839996400Z
OffsetDateTime: 2022-05-17T23:38:32.839996400+07:00

Happy Coding 😊

Java Convert Instant to Calendar

Java Convert Instant to Date

Java Convert Instant to LocalDateTime

Java Convert Instant to LocalDate

Java Convert Instant to LocalTime

Java Convert Instant to ZonedDateTime

Java Convert Instant to Epoch Seconds

Java Convert Instant to Epoch Milliseconds

Java Convert Instant to String

Java Convert String to Instant