Returns a copy of this duration with the nano-of-second part replaced with the specified nano-of-second.
package com.logicbig.example.duration;
import java.time.Duration;
public class WithNanosExample {
public static void main(String... args) {
Duration d = Duration.ofHours(10);
System.out.println(d);
Duration d2 = d.withNanos(2000);
System.out.println(d2);
Duration d3 = Duration.ofNanos(4000000);
System.out.println(d3);
Duration d4 = d3.withNanos(7000);
System.out.println(d4);
}
}
Output
PT10H
PT10H0.000002S
PT0.004S
PT0.000007S