Java Convert SQL Time to LocalTime

Tags: Java SQL Time Java LocalTime Java 8

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

How to convert SQL Time to LocalTime in Java

In Java, with a given Time object we can use the Time.toLocalTime() method to convert it to a LocalTime object as the following example Java program.

ConvertTimeToLocalTimeExample1.java

import java.sql.Time;
import java.time.LocalTime;

public class ConvertTimeToLocalTimeExample1 {
    public static void main(String... args) {
        Time time = new Time(System.currentTimeMillis());

        // Convert Time object to LocalTime object
        LocalTime localTime = time.toLocalTime();

        System.out.println("Time: " + time);
        System.out.println("LocalTime: " + localTime);
    }
}
The output as below.
Time: 21:51:32
LocalTime: 21:51:32

Happy Coding 😊

Java Convert LocalTime to SQL Time