This methods returns a temporal object of the same type as of the input temporal type, with this duration added.
package com.logicbig.example.duration;
import java.time.Duration;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
public class AddToExample {
public static void main(String... args) {
Duration d = Duration.of(10, ChronoUnit.SECONDS);
System.out.println(d);
LocalTime t = LocalTime.now();
System.out.println(t);
Temporal t2 = d.addTo(t);
System.out.println(t2);
}
}
Output
PT10S
15:59:49.742
15:59:59.742