I want to compare WebElements dates to validate if the sorting is correct. However, the values of the dates are for example as follows: "April 5th 2021 12:30pm", "October 22nd 2018 09:18am", "February 1st 2015 11:36pm",
I have tried the below code, but it's returning 1970 as the date and an error for the cases where the day is 2 digits:
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MMMM d yyyy HH:mma", Locale.US);
LocalDate date = LocalDate.parse(dt, dateFormatter);
// or
Date sdf = new SimpleDateFormat("MMMM d u hh:mma").parse(dt);