Java中的Duration minusSeconds()方法
可以使用minusSeconds()Java的Duration类中的方法来获取持续时间的不变副本,其中从中删除了几秒钟。此方法需要一个参数,即要减去的秒数,并返回带有减去的秒数的持续时间。
演示此的程序如下所示-
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ofMinutes(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with 10 seconds removed from the duration is: " + d.minusSeconds(10));
}
}输出结果
The duration is: PT1M A copy with 10 seconds removed from the duration is: PT50S
现在让我们了解上面的程序。
首先,显示持续时间。然后,使用该minusSeconds()方法获得删除10秒的持续时间的不变副本,并显示出来。演示这的代码片段如下-
Duration d = Duration.ofMinutes(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with 10 seconds removed from the duration is: " + d.minusSeconds(10));热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短