java.time.Period.between()
方法獲取表示兩個LocalDate
對象之間的Period
。
聲明
以下是java.time.Period.between()
方法的聲明。
public static Period between(LocalDate startInclusive, LocalDate endExclusive)
參數
startInclusive
- 開始日期,包括,不為null
。endExclusive
- 結束日期,獨佔,非null
。
返回值
一個句點,不是null
。
示例
以下示例顯示了java.time.Period.between()
方法的用法。
package com.zaixian;
import java.time.LocalDate;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.between(LocalDate.ofYearDay(2017, 200),
LocalDate.ofYearDay(2017, 300));
System.out.println(period);
}
}
編譯並運行上面的程式,這將產生以下結果 -
P3M8D
上一篇:
java.time.Period類
下一篇:
java.time.Year類