Java中的即时isSupported()方法
可以使用isSupported()Java的Instant类中的方法来检查Instant类是否支持ChronoUnit。此方法需要单个参数,即ChronoUnit进行检查。如果Instant类支持ChronoUnit,则返回true,否则返回false。
演示此的程序如下所示-
示例
import java.time.*;
import java.time.temporal.ChronoUnit;
public class Demo {
public static void main(String[] args) {
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
boolean flag = i.isSupported(ChronoUnit.SECONDS);
if(flag)
System.out.println("The ChronoUnit SECONDS is supported");
else
System.out.println("The ChronoUnit SECONDS is not supported");
}
}输出结果
The current instant is: 2019-02-13T07:08:32.900Z The ChronoUnit SECONDS is supported
现在让我们了解上面的程序。
首先显示当前时刻。然后使用该isSupported()方法检查Instant类是否支持ChronoUnitSECONDS。返回的值存储在标志中,并打印相应的响应。演示这的代码片段如下-
Instant i = Instant.now();
System.out.println("The current instant is: " + i);
boolean flag = i.isSupported(ChronoUnit.SECONDS);
if(flag)
System.out.println("The ChronoUnit SECONDS is supported");
else
System.out.println("The ChronoUnit SECONDS is not supported");热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿