public static Period dateSubtract(Date startSecond, Date endSecond){
long startInstant = startSecond.getTime();
long endInstant = endSecond.getTime();
LocalDate dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(startInstant), ZoneId.systemDefault()).toLocalDate();
LocalDate endLocalDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(endInstant), ZoneId.systemDefault()).toLocalDate();
int day = (int)ChronoUnit.DAYS.between(dateTime, endLocalDate);
int month = (int)ChronoUnit.MONTHS.between(dateTime, endLocalDate);
int year = (int)ChronoUnit.YEARS.between(dateTime, endLocalDate);
Period period = Period.of(year, month, day);
return period;
}
如果直接用Period.between()这是个坑 如果少于30天 天的计算没问题 多了就会有问题 年月一样的问题