- java.time 包类
- java.time - 主页
- java.time - 时钟
- java.time - 持续时间
- java.time - 即时
- java.time - 本地日期
- java.time - 本地日期时间
- java.time - 本地时间
- java.time - 月日
- java.time - 偏移日期时间
- java.time - 偏移时间
- java.time - 时期
- java.time - 年份
- java.time - 年月份
- java.time - 区域日期时间
- java.time - 区域 ID
- java.time - 区域偏移量
- java.time 包枚举
- java.time - 月份
- java.time 有用资源
- java.time - 讨论
java.time.Period.between() 方法示例
描述
java.time.Period.between() 方法获取表示两个 LocalDate 对象之间的 Period。
声明
以下是 java.time.Period.between() 方法的声明。
public static Period between(LocalDate startInclusive, LocalDate endExclusive)
参数
startInclusive − 包含开始日期,非空。
endExclusive − 排除结束日期,非空。
返回值
非空的 Period。
示例
以下示例展示了 java.time.Period.between() 方法的用法。
package com.tutorialspoint;
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
广告