I am trying to convert an array of strings to a Date ArrayList with the following format - "dd/MM/yyyy" I have included my method below. When I print the ArrayList the dates are not formatted correctly and are displayed as: "Thu Mar 05 00:00:00 GMT 2020" Can anyone think why this is happening?
private void convertDates()
{
SimpleDateFormat formatter1=new SimpleDateFormat("dd/MM/yyyy");
for (String dateString : date) {
try {
dateList.add(formatter1.parse(dateString));
} catch (ParseException e) {
e.printStackTrace();
}
}
displayDates.setText(Arrays.toString(dateList.toArray()));
}
You have a list of
Date
objects, and when you format them to a string, they'll use their default formatting, regardless of the format you used to parse them. If you want to display them in that format, you'll have to do so explicitly. E.g.: