Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java age from date

LocalDate today = LocalDate.now();
LocalDate birthday = LocalDate.of(1987, 09, 24);

Period period = Period.between(birthday, today);

//Now access the values as below
System.out.println(period.getDays());
System.out.println(period.getMonths());
System.out.println(period.getYears());
Comment

age in java



public class AgeCalculator {

    public static int calculateAge(LocalDate birthDate, LocalDate currentDate) {
        if ((birthDate != null) && (currentDate != null)) {
            return Period.between(birthDate, currentDate).getYears();
        } else {
            return 0;
        }
    }
}


Comment

PREVIOUS NEXT
Code Example
Java :: starting code of java 
Java :: java lambda foreach multiple statements 
Java :: nanotime to milliseconds java 
Java :: The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 
Java :: lombok ignore getter e setter 
Java :: java stream collect to arraylist 
Java :: java random numbers in specific range 
Java :: java get current milliseconds 
Java :: how to get an array as input in java 
Java :: java file dialog 
Java :: refresh activity android 
Java :: how can I split string according to space in java? 
Java :: array to map java2 
Java :: how to hide status bar in android studio kotlin 
Java :: apk full form 
Java :: remove last character from string 
Java :: reading in lines from a file java 
Java :: init cap java 
Java :: java for map 
Java :: how to send file in request body rest assured 
Java :: how to make jframe visible 
Java :: java for schleife 
Java :: spring security default username 
Java :: java copy list 
Java :: java botton code 
Java :: how to convert a hexadecimal number to a decimal inside a println in java 
Java :: how to print text in java 
Java :: java initialize map with values in one line 
Java :: Not supported for DML operations 
Java :: java loop through arraylist 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =