Solution was given at Stack -
Calculate age from BirthDate[
^]
Using Kotlin
fun getAge(year: Int, month: Int, dayOfMonth: Int): Int {
return Period.between(
LocalDate.of(year, month, dayOfMonth),
LocalDate.now()
).years
return getAge;
}
Imports needed to use java.time (java 8+)
import java.time.LocalDate;
import java.time.Period
There's API Desugaring now in Android, which makes (a subset of) java.time directly available (no backport library needed anymore) to API levels below 26 (not really down to version 1, but will do for most of the API levels that should be supported nowadays).
For projects supporting Java 6 or 7, this functionality is available via the
ThreeTenBP[
^],
while there is special version, the
ThreeTenABP [
^] for API levels below 26 in Android.