Java Date Time - Duration multipliedBy(long multiplicand) example








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

Syntax

multipliedBy has the following syntax.

public Duration multipliedBy(long multiplicand)

Example

The following example shows how to use multipliedBy.

import java.time.Duration;
import java.time.LocalTime;
/*from  w  w w  .j  a  va 2  s . c  om*/
public class Main {
  public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT,LocalTime.NOON);
    System.out.println(duration.getSeconds());
    
    duration = duration.multipliedBy(2);
    
    System.out.println(duration.getSeconds());

  }
}

The code above generates the following result.