Example 1 — Go Back by One Nanosecond
Subtract one nanosecond and half a second from 10:30:15.
import java.time.LocalDateTime;
public class LdtMinusNanosDemo {
public static void main(String[] args) {
LocalDateTime base = LocalDateTime.of(2026, 3, 15, 10, 30, 15);
System.out.println("base: " + base);
System.out.println("minus 1 ns: " + base.minusNanos(1));
System.out.println("minus 0.5 s: " + base.minusNanos(500_000_000));
}
} How It Works
- The base. 10:30:15 with no fraction.
- One nanosecond back. The time falls into the previous second, 10:30:14, with a fraction of .999999999.
- Half a second back.
500_000_000nanoseconds gives 10:30:14.500.

