Java LocalDateTime toLocalDate() Method
Example
Get only the date 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.toLocalDate());
}
}
Definition and Usage
The toLocalDate() method returns the date part (year, month and day) of a LocalDateTime, as a LocalDate object. The time is left out.
Tip: Use the toLocalTime() method to get the time part.
Syntax
public LocalDate toLocalDate()
Parameter Values
None.
Technical Details
| Returns: | A LocalDate object with the same year, month and day. |
|---|
Related Pages
❮ Date and Time Methods