Java中的Duration零字段
ZERO字段在Java的Duration类中将持续时间设置为零。此字段与Java中不同数据类型中的null值完全相同。
演示零字段的程序如下所示-
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ZERO;
boolean flag = d.isZero();
System.out.println("The duration is: " + d);
if(flag)
System.out.println("The above duration is of zero length");
else
System.out.println("The above duration is not of zero length");
}
}输出结果
The duration is: PT0S The above duration is of zero length
现在让我们了解上面的程序。
首先,使用零字段将持续时间设置为零,然后将其显示。然后flag保存isZero()方法的返回值。根据标志中的值,持续时间的长度是否为零,并进行打印。演示这的代码片段如下-
Duration d = Duration.ZERO;
boolean flag = d.isZero();
System.out.println("The duration is: " + d);
if(flag)
System.out.println("The above duration is of zero length");
else
System.out.println("The above duration is not of zero length");热门推荐
10 枣庄人事考试祝福语简短
11 二胎祝福语简短霸气
12 同学道别祝福语简短
13 六一加端午祝福语简短
14 祝福语简短七夕
15 哥哥祝福语简短霸气句子
16 关于扬州的祝福语简短
17 老婆生日祝福语短句简短
18 创业大吉祝福语简短