+ 1
How to calculate age by using birthday?
3 Answers
+ 11
@Raphael
This won't work for birthdays that will be later in the current year than current date.
Use Date class, you can find a tutorial there:
https://www.tutorialspoint.com/java/java_date_time.htm
+ 3
You just need to do subtraction of the actual year by birthday:
Java example:
public class HowOld {
public static void main (String[] args) {
int birthday = 2000;
int actualYear = 2016;
int old;
old = actualYear - birthday; // (2016 - 2000 = 16 years)
System.out.println(old); // Shows: 16.
}
}
+ 3
@Tashi
Thanks! I dont nave think this possibilite! :)