Duration plus(Duration) method in Java with Examples Last Updated : 26 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The plus(Duration) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified duration added, passed as the parameter. Syntax: public Duration plus(Duration duration) Parameters: This method accepts a parameter duration which is the duration to be added. It can be positive or negative but not null. Return Value: This method returns a Duration which is an immutable copy of the existing duration with the parameter amount of duration added to it. Exception: This method throws ArithmeticException if numeric overflow occurs. Below examples illustrate the Duration.plus() method: Example 1: Java // Java code to illustrate plus() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Duration 1 using parse() method Duration duration1 = Duration.parse("P2DT3H4M"); // Duration 2 using ofHours() method Duration duration2 = Duration.ofHours(5); // Get the duration added // using plus() method System.out.println(duration1 .plus(duration2)); } } Output: PT56H4M Example 2: Java // Java code to illustrate plus() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Duration 1 using parse() method Duration duration1 = Duration.parse("P0DT0H4M"); // Duration 2 using ofHours() method Duration duration2 = Duration.ofDays(5); // Get the duration added // using plus() method System.out.println(duration1 .plus(duration2)); } } Output: PT120H4M Reference: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#plus-java.time.Duration- Comment More infoAdvertise with us Next Article Duration abs() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-time package Java-Duration Practice Tags : Java Similar Reads Duration minus(Duration) method in Java with Examples The minus(Duration) method of Duration Class in java.time package is used to get an immutable copy of this duration with the specified duration subtracted, passed as the parameter.Syntax: public Duration minus(Duration duration) Parameters: This method accepts a parameter duration which is the durat 2 min read Duration equals(Duration) method in Java with Examples The equals(Duration) method of Duration Class in java.time package is used to check whether this duration is equal to the duration passed as the parameter. Syntax: public boolean equals(Duration otherDuration) Parameters: This method accepts a parameter otherDuration which is the duration to which t 2 min read Duration dividedBy(Duration) method in Java with Examples The dividedBy(Duration) method of Duration Class in java.time package is used to get an immutable copy of this duration divided by the duration passed as the parameter. Syntax: public Duration dividedBy(Duration divisor) Parameters: This method accepts a parameter divisor which is the duration to be 2 min read Duration compareTo(Duration) method in Java with Examples The compareTo(Duration) method of Duration Class in java.time package is used to compare this duration with the duration passed as the parameter. Syntax: public int compareTo(Duration otherDuration) Parameters: This method accepts a parameter otherDuration which is the duration to which this duratio 2 min read Duration abs() method in Java with Examples The abs() method of Duration Class in java.time package is used to get an immutable copy of this duration with the absolute duration. Syntax: public Duration abs() Parameters: This method do not accepts any parameter. Return Value: This method returns a Duration which is an immutable copy of the exi 1 min read Duration addTo(Temporal) method in Java with Examples The addTo(Temporal) method of Duration Class in java.time package is used add this duration to the specified temporal object, passed as the parameter. Syntax: public Temporal addTo?(Temporal temporalObject) Parameters: This method accepts a parameter temporalObject which is the amount to be adjusted 2 min read Like