Close

Java Date Time - Duration.addTo() Examples

Java Date Time Java Java API 


Class:

java.time.Duration

java.lang.Objectjava.lang.Objectjava.time.Durationjava.time.Durationjava.time.temporal.TemporalAmountTemporalAmountjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public Temporal addTo(Temporal temporal)

This methods returns a temporal object of the same type as of the input temporal type, with this duration added.

Examples


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




See Also