Java Convert LocalDateTime to LocalTime

Tags: Java LocalDateTime Java LocalTime Java 8

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

How to convert LocalDateTime to LocalTime in Java

In Java with a given LocalDateTime object we can use the toLocalTime() method to get the time value and return a LocalTime object. In the following Java program we learn how to use the LocalDateTime.toLocalTime() method to convert a LocalDateTime object to LocalTime object.

ConvertLocalDateTimeToLocalTimeExample1.java

import java.time.LocalDateTime;
import java.time.LocalTime;

public class ConvertLocalDateTimeToLocalTimeExample1 {
    public static void main(String... args) {
        LocalDateTime localDateTime = LocalDateTime.now();
        LocalTime LocalTime = localDateTime.toLocalTime();

        System.out.println("LocalDateTime: " + localDateTime);
        System.out.println("LocalTime: " + LocalTime);
    }
}
The output as below.
LocalDateTime: 2022-04-24T11:14:53.504532900
LocalTime: 11:14:53.504532900

Happy Coding 😊

Java Convert LocalDateTime to String

Java Convert LocalDateTime to LocalDate

Java Convert LocalDateTime to OffsetDateTime

Java Convert LocalDateTime to ZonedDateTime

Java Convert LocalDateTime to Calendar

Java Convert LocalDateTime to Date

Java Convert LocalDateTime to Instant

Java Convert LocalDateTime to Epoch Seconds

Java Convert Epoch Seconds to LocalDateTime

Java Compare two LocalDateTime Values

Java Compare two LocalTime Values

Java LocalTime by Examples

Java LocalDate by Examples

Java LocalDateTime by Examples

Java Date by Examples

Java Calendar by Examples

Java Calendar using Calendar.Builder by Examples