Java中的即时minusNanos()方法
可以使用minusNanos()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 subtracted is: " + i.minusNanos(1000000000));
}
}输出结果
The current instant is: 2019-02-12T12:36:26.511Z An instant with 1000000000 nanoseconds subtracted is: 2019-02-12T12:36:25.511Z
现在让我们了解上面的程序。
首先显示当前时刻。然后,使用该minusNanos()方法获得减去1000000000纳秒的不变时刻的副本,并显示出来。演示这的代码片段如下-
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
System.out.println("An instant with 1000000000 nanoseconds subtracted is: " + i.minusNanos(1000000000));热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短