java.time.Period.negated()
方法返回此Period
的副本,其长度为negated
。
声明
以下是java.time.Period.negated()
方法的声明。
public Period negated()
返回值
一个基于此Period
的Period
,总数为负值,不为null
。
异常
ArithmeticException
- 如果发生数字溢出。
示例
以下示例显示了java.time.Period.negated()
方法的用法。
package com.yiibai;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.ofDays(5);
System.out.println(period.getDays());
Period period1 = period.negated();
System.out.println(period1.getDays());
}
}
执行上面示例代码,得到以下结果:
5
-5