I have a question, as far as dates are concerned in Java. I receive several dates in String format but each of them comes in a different format, so they do not come in a certain format.
Dates with formats such as:
- 21/05 / 2018Z09: 14: 32.123
- 05/21/2018
- 05-21-2018 / 09: 14: 32
- 05-21-2018 09:14:32
And so many more dates ...
The goal is to pass these dates to a specific format. which would be the following: 2018-05-21 09:14:32 - > (yyyy-MM-dd HH: mm: ss).
I do not know if I do not understand the SimpleDateFormat correctly, but I can not return the date in the format I want.
Date fecha = new Date("2018-01-23T09:56:04+01:00");
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String strDate = sdf.format(fecha);
Date dates = new Date();
try {
dates = dateFormat.parse(strDate);
System.out.println(sdf.format(dates));
} catch (ParseException ex) {
//
}