Java Convert Instant to LocalTime
Tags: Java Instant Java LocalTime Java 8
In this Java core tutorial we learn how to convert a java.time.Instant object into a java.time.LocalTime object in Java programming language.
How to convert Instant to LocalTime in Java
In Java, with a given Instant object we can use the LocalTime.ofInstant(Instant instant, ZoneId zone) static method to convert it to a LocalTime object based on system time zone as the following example Java code.
ConvertInstantToLocalTimeExample1.java
import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
public class ConvertInstantToLocalTimeExample1 {
public static void main(String... args) {
Instant instant = Instant.now();
LocalTime localTime = LocalTime.ofInstant(instant, ZoneId.systemDefault());
System.out.println("Instant: " + instant);
System.out.println("LocalTime: " + localTime);
}
}
Instant: 2022-05-17T16:35:46.702029600Z
LocalTime: 23:35:46.702029600
Happy Coding 😊
Related Articles
Java Convert Instant to Calendar
Java Convert Instant to LocalDateTime
Java Convert Instant to LocalDate
Java Convert Instant to ZonedDateTime
Java Convert Instant to OffsetDateTime
Java Convert Instant to Epoch Seconds
Java Convert Instant to Epoch Milliseconds