Period isZero() 方法在 Java 中
在 Java 中可以使用 Period 类中的 isZero() 方法检查 Period 中的日、月和年是否为零。此方法不需要参数。此外,如果 Period 中的日、月和年为零,则它返回 true,否则返回 false。
演示此内容的程序如下
示例
import java.time.Period;
public class Demo {
public static void main(String[] args) {
String period = "P0Y0M0D";
Period p = Period.parse(period);
System.out.println("The Period is: " + p);
System.out.println("The days, months and years in the Period are zero? " + p.isZero());
}
}输出
The Period is: P0D The days, months and years in the Period are zero? true
现在让我们来了解一下上面的程序。
首先显示 Period。然后使用 isZero() 方法检查 Period 中的日、月和年是否为零,并显示返回值。演示此内容的代码片段如下
String period = "P0Y0M0D";
Period p = Period.parse(period);
System.out.println("The Period is: " + p);
System.out.println("The days, months and years in the Period are zero? " + p.isZero());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP