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