I want to put in a constructor an argument of type Date, so I thought that the best way to do that is to write a method that transforms a string into a date. Which is the easiest way to check if my string is a valid date?
This is my constructor:
Product product = new Product("Produs 1", 312.33, updateDate("23/12/2018"));
And this is the method that transforms the String into a Date.
public static Date updateDate(String date) {
Date newDate = new Date();
try {
DateFormat dtF = new SimpleDateFormat("dd/MM/yyyy");
newDate = dtF.parse(date);
return newDate;
} catch (ParseException e) {
e.printStackTrace();
}
return newDate;
}