Java中的即时plusNanos()方法
可以使用plusNanos()Java中Instant类中的方法来获取添加了几纳秒的瞬间的不变副本。此方法需要单个参数,即要添加的纳秒数,并且它会返回添加了纳秒的瞬间。
演示此的程序如下所示-
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
System.out.println("An instant with 1000000000 nanoseconds added is: " + i.plusNanos(1000000000));
}
}输出结果
The current instant is: 2019-02-12T12:26:03.868Z An instant with 1000000000 nanoseconds added is: 2019-02-12T12:26:04.868Z
现在让我们了解上面的程序。
首先显示当前时刻。然后,使用该plusNanos()方法获得添加了1000000000纳秒的不变时刻的副本,并显示出来。演示这的代码片段如下-
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
System.out.println("An instant with 1000000000 nanoseconds added is: " + i.plusNanos(1000000000));热门推荐
10 圣诞祝福语简短给师姐
11 六一祝福语简短十六字
12 简短的古文春节祝福语
13 朋友新工作祝福语简短
14 新房上梁简短祝福语大全
15 保洁阿姨送来祝福语简短
16 节日祝福语大全简短创意
17 牛年大气简短的祝福语
18 国庆节日简短祝福语