Java LocalDateTime toLocalTime() Method
Example
Get only the time from a date and time:
import java.time.LocalDateTime;
public class Main {
public static void main(String[] args) {
LocalDateTime myDateTime = LocalDateTime.of(2026, 1, 15, 14, 30);
System.out.println(myDateTime);
System.out.println(myDateTime.toLocalTime());
}
}
Definition and Usage
The toLocalTime() method returns the time part (hour, minute, second and nanosecond) of a LocalDateTime, as a LocalTime object. The date is left out.
Tip: Use the toLocalDate() method to get the date part.
Syntax
public LocalTime toLocalTime()
Parameter Values
None.
Technical Details
| Returns: | A LocalTime object with the same time. |
|---|
Related Pages
❮ Date and Time Methods