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
上一篇: 理解C++类的继承方式(小白)
下一篇: 58VIP账号发贴器