[Java] How to calculate age using LocalDate

How to calculate the current age from your birthday using java.time.LocalDate.


public int getAge(int year, int month, int day) {

    //Birthday to be calculated
    LocalDate birthday = LocalDate.of(year, month, day);

    //Current date
    LocalDate today = LocalDate.now();

    long duration = ChronoUnit.YEARS.between(birthday, today);

    return (int)duration;

LocalDate (Java Platform SE 8)

Recommended Posts

[Java] How to calculate age using LocalDate
[Java] How to operate List using Stream API
[Java] How to use Map
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
Java --How to make JTable
How to use java Optional
How to minimize Java images
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
How to use Java Map
How to set Java constants
How to convert A to a and a to A using AND and OR in Java
How to use Java variables
How to convert Java radix
[Java] How to implement multithreading
[Java] How to use Optional ①
How to initialize Java array
How to authorize using graphql-ruby
How to play MIDI files using the Java Sound API
How to study Java Silver SE 8
How to use Java HttpClient (Get)
[Java] How to update Java on Windows
How to disassemble Java class files
[Java] How to use join method
How to learn JAVA in 7 days
[Processing × Java] How to use variables
[Java] How to create a folder
How to decompile java class files
[Java] How to use LinkedHashMap class
How to convert LocalDate and Timestamp
[JavaFX] [Java8] How to use GridPane
How to write Java variable declaration
[Java] Try to implement using generics
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
How to name variables in Java
How to pass Oracle Java Silver
How to turn Iterator Dojo (Java)
java Eclipse How to debug javaScript
[Processing × Java] How to use arrays
How to make a Java array
How to use Java lambda expressions
I tried using Java memo LocalDate
How to build CloudStack using Docker
[Java] How to use Math class
How to find Java prime numbers
How to use Java enum type
How to concatenate strings in java
How to solve the unknown error when using slf4j in Java
How to make a groundbreaking diamond using Java for statement wwww
How to check Java installed on Mac
How to execute a contract using web3j
How to make a Java calendar Summary
How to implement date calculation in Java
How to implement Kalman filter in Java