Java中的即时plusSeconds()方法
可以使用JavaInstant类中的plusSeconds()方法来获取添加了几秒钟的即时不变的副本。该方法需要一个参数,即要添加的秒数,并且返回带有添加的秒数的瞬间。
演示此的程序如下所示-
示例
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 10 seconds added is: " + i.plusSeconds(10));
}
}输出结果
The current instant is: 2019-02-12T12:23:14.131Z An instant with 10 seconds added is: 2019-02-12T12:23:24.131Z
现在让我们了解上面的程序。
首先显示当前时刻。然后使用该plusSeconds()方法获得添加了10秒的不变时刻的副本,并显示出来。演示这的代码片段如下-
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
System.out.println("An instant with 10 seconds added is: " + i.plusSeconds(10));热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短