duration java
持续时间类multipliedBy()方法 (Duration Class multipliedBy() method)
multipliedBy() method is available in java.time package.
在java.time包中提供了multipliedBy()方法 。
multipliedBy() method is used to multiply this Duration by the given value.
使用multipliedBy()方法将此Duration乘以给定值。
multipliedBy() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
multipliedBy()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
multipliedBy() method may throw an exception at the time of performing subtraction.
在执行减法时, multipliedBy()方法可能会引发异常。
ArithmeticException: This exception may throw when the calculated result value exceeds the limit.
ArithmeticException :当计算结果值超过限制时,可能引发此异常。
Syntax:
句法:
public Duration multipliedBy(long val);
Parameter(s):
参数:
long val – represents the value is to be multiplied with this Duration.
long val –表示该值将与此持续时间相乘。
Return value:
返回值:
The return type of this method is Duration, it returns the Duration that holds the value of this Duration multiplied by the given value.
该方法的返回类型为Duration ,它返回的Duration包含此Duration的值乘以给定值。
Example:
例:
// Java program to demonstrate the example
// of multipliedBy(long val) method of Duration
import java.time.*;
public class MultipliedByOfDuration {
public static void main(String args[]) {
long mul_val = 5;
// Instantiates two Duration objects
Duration du1 = Duration.ofHours(10);
Duration du2 = Duration.ofMinutes(25);
// Display du1 and du2
System.out.println("du1: " + du1);
System.out.println("du2: " + du2);
System.out.println("Multiplicand: " + mul_val);
// multiplies this Duration object(du1)
// by the given value (mul_val)
Duration multiplied_val = du1.multipliedBy(mul_val);
System.out.println("du1.multipliedBy(mul_val): " + multiplied_val);
// multiplies this Duration object(du2)
// by the given value (mul_val)
multiplied_val = du2.multipliedBy(mul_val);
System.out.println("du2.multipliedBy(mul_val): " + multiplied_val);
}
}
Output
输出量
du1: PT10H
du2: PT25M
Multiplicand: 5
du1.multipliedBy(mul_val): PT50H
du2.multipliedBy(mul_val): PT2H5M
翻译自: https://www.includehelp.com/java/duration-multipliedby-method-with-example.aspx
duration java