Returns a copy of this duration with the second part replaced with the specified seconds.

package com.logicbig.example.duration;
import java.time.Duration;
public class WithSecondsExample {
public static void main(String... args) {
Duration d = Duration.ofNanos(20);
System.out.println(d);
Duration d2 = d.withSeconds(30);
System.out.println(d2);
}
}
Output
PT0.00000002S
PT30.00000002S