The current code below uses the yyyy-mm-dd format. However the input should look like this (March 2, 1999). How do I calculate it or convert it?
public class CalculateAgeJava8 {
public static void main(String[] args) {
System.out.print("Please enter date of birth: ");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
scanner.close();
LocalDate dob = LocalDate.parse(input);
System.out.println("Age is:" + getAge(dob));
}
public static int getAge(LocalDate dob) {
LocalDate curDate = LocalDate.now();
return Period.between(dob, curDate).getYears();
}
}