Java Convert OffsetDateTime to Date

Tags: Java OffsetDateTime Java Date Java 8

In this Java core tutorial we learn how to convert an OffsetDateTime object to a Date object in Java programming language.

How to convert OffsetDateTime to Date in Java

In Java, with a given OffsetDateTime object we can convert it to a Date object with steps below.

  • First step, convert OffsetDateTime object to an Instant object
  • Second step, instantiate new Date object from an Instant.

ConvertOffsetDateTimeToDateExample1.java

import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Date;

public class ConvertOffsetDateTimeToDateExample1 {
    public static void main(String... args) {
        OffsetDateTime offsetDateTime = OffsetDateTime.now();

        Instant instant = offsetDateTime.toInstant();
        Date date = Date.from(instant);

        System.out.println("OffsetDateTime: " + offsetDateTime);
        System.out.println("Date: " + date);
    }
}
The output as below.
OffsetDateTime: 2022-05-12T23:03:10.866237600+07:00
Date: Thu May 12 23:03:10 ICT 2022

Happy Coding 😊

Java Convert OffsetDateTime to Epoch Seconds

Java Convert OffsetDateTime to ZoneOffset

Java Convert OffsetDateTime to LocalDate

Java Convert OffsetDateTime to LocalTime

Java Convert OffsetDateTime to LocalDateTime

Java Convert OffsetDateTime to ZonedDateTime

Java Convert OffsetDateTime to Instant

Java Convert OffsetDateTime to Calendar

Java Convert OffsetDateTime to OffsetTime

Java Convert OffsetDateTime to String

Java Convert String to OffsetDateTime

Java Convert Date to OffsetDateTime

Java Convert Calendar to OffsetDateTime