I am tryig to convert birthday from String to Date in order to add to the arraylist contacts. Then read from the contacts to display the birthday. However 05/02/1990 becomes 365/12/1990, 06/12/1991 becomes 365/12/1991 (i.e. DD and MM are incorrect). Thank you very much for the help!
ArrayList<Person> contacts = new ArrayList<Person>();
...
String firstName = sc.next();
String lastName = sc.next();
String email = sc.next();
String birthdayStr = sc.next();
SimpleDateFormat formatter = new SimpleDateFormat("DD/MM/YYYY");
try{
Date birthday = formatter.parse(birthdayStr);
Person s = new Person(firstName, lastName, email, birthday);
contacts.add(s);
Date b = s.getBirthday();
System.out.println(formatter.format(b));
}catch(ParseException e){
System.out.println( e.getMessage());
}
Dis day in year, you need lowercasedfor day of month. Use lowercaseyalso.The use of uppercase
Yrelates to week year:To avoid this "side effect" on the year, lowercase
ycan be used.