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 好听的元旦简短祝福语