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 红包祝福语简短10字
18 周六早晨祝福语简短