I have a big problem with a date that I have to formatting in the right way. My proposal of solution following:
...
//Read: 1935-05-12 00:00:00.0
Date dateOfBirth= (Date) arrayOfObject[3];
//Pattern: dd-MM-yyyy hh:mm:ss
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
//12-05-1935 12:00:00 (for me it's perfect but I need Date and no String)
String strDate = dateFormat.format(dateOfBirth);
//Read: Sun May 12 00:00:00 CET 1935
dateOfBirth= dateFormat.parse(strDate);
//Read: Sun May 12 00:00:00 CET 1935
rep.setDateOfBirth(dateOfBirth);
...
I need a format like strDate, because I need this format for the database, but I need a Date and not a String and I don't know how can I formatting in the right way my Date string.
Datealready. ADateis a moment in time. The representation of a date can be a string.SimpleDateFormatandDate. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead useLocalDateTimeandDateTimeFormatter, both from java.time, the modern Java date and time API.1935-05-12 00:00:00.0, it looks like you are really getting ajava.sql.Timestampobject out of your array. It’s another poorly deigned and long outdated class, a subclass ofDateand a true hack on top of it.