jdk8计算年龄

 

LocalDate today = LocalDate.now();
LocalDate playerDate = LocalDate.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").parse("1983-07-08"));
long years = ChronoUnit.YEARS.between(playerDate, today);
log.info(years);

 

 

当前时间为2015-8-12,显示为32

 

 

 

LocalDate today = LocalDate.now();
LocalDate playerDate = LocalDate.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").parse("1983-11-08"));
long years = ChronoUnit.YEARS.between(playerDate, today);
log.info(years);

当前时间为2015-8-12,显示为31

 

 

 

参考:

Java 8 时间日期库的20个使用示例

http://www.php100.com/html/it/biancheng/2015/0318/8807.html

Java8 日期/时间(Date Time)API指南 - ImportNew

http://www.importnew.com/14140.html

你可能感兴趣的:(jdk8)