分别计算毫秒值相减
为什么格式化回来是这样?
使用LocalDate,计算出年份差,月份和日期
String briStr = "1999-12-12";
LocalDate parse = LocalDate.parse(briStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate now = LocalDate.now();
int year = now.getYear() - parse.getYear();
// 判断有没有过完生日
if (now.getMonthValue() - parse.getMonthValue() < 0 ){
year--;
} else if (now.getMonthValue() - parse.getMonthValue() == 0
&& now.getDayOfMonth() - now.getDayOfMonth() < 0) {
year--;
}
System.out.println(year);