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 祝福语驱散霉运的话简短