I am trying to create a service that does a series of operations on a database and then returns a set of information.
Among these information there's the birthdate of a series of customers.
When I try to parse (and then format) this dates I get the error in the title.
The strange thing is that even though the exception is raised, the code still compiles and runs without problems giving me the results I expect...
This is the method:
public String getDataNascitaFormattata() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date data = null;
try {
data = sdf.parse(dataNascita);
dataNascita = new SimpleDateFormat("dd/MM/yyyy").format(data);
} catch (ParseException e) {
System.err.println(e);
}
return dataNascita;
}
And this is an example:
Initial birthdate: "1969-09-07 00:00:00.0"
Desired birthdate: 07/09/1969
Error: java.text.ParseException: Unparseable date: "07/09/1969"
Result (WITH the exception being thrown):
EDIT: I've already tried adding the locale but the exception is still getting thrown...
EDIT2: here is a pic that explains in a better way the situation