Java - multipliedBy( ), dividedBy( ), and negated( ) Methods

Introduction

Multiplication, division, and negation work on Duration and Period.

Durations and periods can be added and subtracted.

The Date-Time API supports negative durations and periods.

Demo

import java.time.Duration;

public class Main {
  public static void main(String[] args) {
    Duration d = Duration.ofSeconds(200); // PT3M20S (3 minutes and 20 seconds)
    System.out.println(d);//from   w w  w. j  ava 2 s.  com
    Duration d1 = d.multipliedBy(2);      // PT6M40S (6 minutes and 40 seconds)
    System.out.println(d1);
    Duration d2 = d.negated();            // PT-3M-20S (-3 minutes and -20 seconds)
    System.out.println(d2);
    
  }
}

Result