Java中的即时get()方法
可以使用get()Java中Instant类中的方法获得Instant所需的ChronoField的值。此方法需要一个参数,即ChronoField,它返回作为参数传递的ChronoField的值。
演示此的程序如下所示-
示例
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class Demo {
public static void main(String[] args) {
Instant i = Instant.now();
int micro = i.get(ChronoField.MICRO_OF_SECOND);
System.out.println("The current Instant is: " + i);
System.out.println("The MICRO_OF_SECOND Field is: " + micro);
}
}输出结果
The current Instant is: 2019-02-13T11:07:48.456Z The MICRO_OF_SECOND Field is: 456000
现在让我们了解上面的程序。
首先,显示当前时刻。然后,使用该get()方法获取并显示MICRO_OF_SECONDChronoField的值。演示这的代码片段如下-
Instant i = Instant.now();
int micro = i.get(ChronoField.MICRO_OF_SECOND);
System.out.println("The current Instant is: " + i);
System.out.println("The MICRO_OF_SECOND Field is: " + micro);热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语