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

calculate age from localdate java

public int calculateAge(
  LocalDate birthDate,
  LocalDate currentDate) {
    // validate inputs ...
    return Period.between(birthDate, currentDate).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 :: spring boot security maven 
Java :: main code of java 
Java :: java dictionary foreach 
Java :: java check if number is even 
Java :: empty character in java 
Java :: java min integer 
Java :: java time code 
Java :: Could not initialize class org.apache.maven.plugin.war.util.WebappStructureSerializer 
Java :: java cmd install raspbian 
Java :: Thread inline ajva 
Java :: print list in java 
Java :: Failed to resolve org.junit.platform:junit-platform-launcher:1.7.0 
Java :: android java increment hashmap value 
Java :: android essential plugin missing 
Java :: java delete directory 
Java :: how to format ddmmmyyyy to ddmmyy in java 
Java :: listview refresh android adapter 
Java :: set text size programmatically android 
Java :: java string join arraylist 
Java :: java lombok constructor inject guice 
Java :: mostrar todos los elementos de un arraylist java 
Java :: java take screenshot 
Java :: gradle build with javadoc 
Java :: javafx get window in controller 
Java :: java array kürzen 
Java :: turn off focus border java 
Java :: append to file in java 
Java :: how to delete a file in java 
Java :: how to convert string to double in android studio 
Java :: java parse xml string 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =