Period isNegative() 方法在 Java 中
在 Java 中的 Period 类中的 isNegative() 方法中,可以检查 Period 中的天、月和年是否为负。
此方法不需要参数。此外,如果 Period 中的任意天、月和年为负,则返回 true,如果 Period 中的所有天、月和年均为正,则返回 false。
一个展示此问题的方法如下
import java.time.Period;
public class Demo {
public static void main(String[] args) {
String period = "P5Y9M4D";
Period p = Period.parse(period);
System.out.println("The Period is: " + p);
System.out.println("The days, months and years in the Period are negative? " + p.isNegative());
}
}实时演示
The Period is: P5Y9M4D The days, months and years in the Period are negative? false
输出
现在让我们理解一下上述程序。
String period = "P5Y9M4D";
Period p = Period.parse(period);
System.out.println("The Period is: " + p);
System.out.println("The days, months and years in the Period are negative? " +
p.isNegative());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP