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.yiibai;
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