欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jdk8计算年龄

程序员文章站 2022-04-08 18:40:15
...

 

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