s-day01--Period类(日期间隔)

This commit is contained in:
xx
2026-10-13 10:47:45 +08:00
parent 854c97c66b
commit c0cfc979bb
@@ -0,0 +1,19 @@
package com.inmind.jdk8_time04;
import java.time.LocalDate;
import java.time.Period;
/**
* 目标:掌握Period的作用:计算机两个日期相差的年数,月数、天数。
注意:只能两个计算LocalDate对象之间的间隔
*/
public class PeriodDemo13 {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();
LocalDate bir = LocalDate.of(1989, 8, 1);
//某人从出生到现在活了多少年月日
Period period = Period.between(bir,localDate);
System.out.println(period.getYears());
System.out.println(period.getMonths());
System.out.println(period.getDays());
}
}