java.time.Duration.multipliedBy() Method Example



Description

The java.time.Duration.multipliedBy(long multiplicand) method returns a copy of this duration multiplied by the scalar.

Declaration

Following is the declaration for java.time.Duration.multipliedBy(long multiplicand) method.

public Duration multipliedBy(long multiplicand)

Parameters

multiplicand − the value to multiply the duration by, positive or negative.

Return Value

a Duration based on this duration multiplied by the specified scalar, not null.

Exception

ArithmeticException − if numeric overflow occurs.

Example

The following example shows the usage of java.time.Duration.multipliedBy(long multiplicand) method.

package com.tutorialspoint;

import java.time.Duration;

public class DurationDemo {
   public static void main(String[] args) {

      Duration duration = Duration.ofSeconds(5);
      System.out.println(duration.getSeconds());
      Duration duration1 = duration.multipliedBy(3);
      System.out.println(duration1.getSeconds());
   }
}

Let us compile and run the above program, this will produce the following result −

5
15
Advertisements