Java中的Duration plusNanos()方法
可以使用plusNanos()Java的Duration类中的方法来获取持续时间的不变副本,在其中添加了几纳秒的时间。此方法需要一个参数,即要添加的纳秒数,并且它返回添加了纳秒的持续时间。
演示此的程序如下所示-
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ofSeconds(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with 100 nano seconds added to the duration is: " + d.plusNanos(100));
}
}输出结果
The duration is: PT1S A copy with 100 nano seconds added to the duration is: PT1.0000001S
现在让我们了解上面的程序。
首先,显示持续时间。然后,使用该plusNanos()方法获得添加了10纳秒的持续时间的不变副本,并将其显示出来。演示这的代码片段如下-
Duration d = Duration.ofSeconds(1);
System.out.println("The duration is: " + d);
System.out.println("A copy with 100 nano seconds added to the duration is: " + d.plusNanos(100));热门推荐
10 同事换单位简短祝福语
11 谢谢朋友的祝福语简短
12 立秋节气简短祝福语
13 新房祝福语简短10字
14 长辈新年祝福语大全简短
15 新年给大家简短祝福语
16 生日祝福语简短独特姑姑
17 芭比的婚礼祝福语简短
18 邀请新人祝福语简短英文