Java中的duration negated()方法
可以使用Java中的Duration类中的negated()方法来获得一个否定了持续时间的不变副本。此方法不需要任何参数,并且返回取反的持续时间。另外,如果发生数字溢出,则会引发ArithmeticException。
演示此的程序如下所示-
示例
import java.time.Duration;
public class GFG {
public static void main(String[] args) {
Duration d = Duration.ofHours(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with negated duration is: " + d.negated());
}
}输出结果
The duration is: PT1H A copy with negated duration is: PT-1H
现在让我们了解上面的程序。
使用negated()方法可获得一个否定的持续时间不变副本。然后显示。演示这的代码片段如下-
Duration d = Duration.ofHours(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with negated duration is: " + d.negated());热门推荐
10 祖国祝福语简短走心
11 公司生日祝福语员工简短
12 老师给家长祝福语简短
13 滑稽搞笑结婚祝福语简短
14 送给新娘祝福语简短高级
15 换工作简短特别祝福语
16 爱心大叔生日祝福语简短
17 英文节日祝福语简短唯美
18 求婚蛋糕卡片祝福语简短