Java Duration multiplication, division, and negation

Description

Java Duration multiplication, division, and negation

import java.time.Duration;

public class Main {
  public static void main(String[] args) {
    Duration d = Duration.ofSeconds(100); // PT1M40S (1 minute and 40 seconds)
    System.out.println(d);//  w  ww .  ja v a  2 s.  c  o m
    Duration d1 = d.multipliedBy(2);      // PT3M20S (3 minutes and 20 seconds)
    System.out.println(d1);
    Duration d2 = d.negated();            // PT-1M-40S (-1 minutes and -40 seconds)
    System.out.println(d2);
    
  }
}



PreviousNext

Related