Java Convert OffsetDateTime to OffsetTime
Tags: Java OffsetDateTime Java OffsetTime Java 8
In this Java core tutorial we learn how to convert an OffsetDateTime object to an OffsetTime object in Java programming language.
How to convert OffsetDateTime to OffsetTime in Java
In Java, with a given OffsetDateTime object we can use the to the toOffsetTime() method to convert it to an OffsetTime object as the example Java code below.
ConvertOffsetDateTimeToOffsetTimeExample1.java
import java.time.OffsetDateTime;
import java.time.OffsetTime;
public class ConvertOffsetDateTimeToOffsetTimeExample1 {
public static void main(String... args) {
OffsetDateTime offsetDateTime = OffsetDateTime.parse("2022-05-08T14:10:20.878564600+02:00");
OffsetTime offsetTime = offsetDateTime.toOffsetTime();
System.out.println("OffsetDateTime: " + offsetDateTime);
System.out.println("OffsetTime: " + offsetTime);
}
}
OffsetDateTime: 2022-05-08T14:10:20.878564600+02:00
OffsetTime: 14:10:20.878564600+02:00
Happy Coding 😊
Related Articles
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 Date
Java Convert OffsetDateTime to Calendar
Java Convert OffsetDateTime to String
Java Convert String to OffsetDateTime