Example 1 — Add Half a Second
Add 500,000,000 nanoseconds, which is half a second, to 10:30.
import java.time.LocalDateTime;
public class LdtPlusNanosDemo {
public static void main(String[] args) {
LocalDateTime start = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime later = start.plusNanos(500_000_000);
System.out.println("start: " + start);
System.out.println("later: " + later);
}
} How It Works
- The start. 10:30 on 15 March 2026.
- Half a second.
500_000_000nanoseconds is 0.5 seconds. The underscores only make the number easier to read. - A fraction appears. The result prints as
10:30:00.500, so the zero seconds are shown once there is a fraction.

