Example 1 — Cut to the Day, the Hour, and the Minute
Take one date-time with a long fraction, and cut it to three different units.
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class LdtTruncatedToDemo {
public static void main(String[] args) {
LocalDateTime dt = LocalDateTime.of(2026, 3, 15, 14, 30, 45, 123_456_789);
System.out.println("original: " + dt);
System.out.println("DAYS: " + dt.truncatedTo(ChronoUnit.DAYS));
System.out.println("HOURS: " + dt.truncatedTo(ChronoUnit.HOURS));
System.out.println("MINUTES: " + dt.truncatedTo(ChronoUnit.MINUTES));
}
} How It Works
- A very exact value. It has seconds and a 9-digit fraction.
- DAYS. The whole time of day is cleared, so the result is midnight,
00:00. - HOURS. The minutes, seconds, and fraction are cleared, which gives
14:00. - MINUTES. The seconds and the fraction are cleared, which gives
14:30.

