I have following date in String.
"2022-02-01T20:32:00.000Z"
And i want to format this date to following pattern
MM/dd/yyyy HH:mm:ss a
I tried following solution from another StackOverflow question.
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
LocalDate date = LocalDate.parse("2022-02-01T20:32:00.000Z", inputFormatter);
String formattedDate = outputFormatter.format(date);
System.out.println(formattedDate); //02/01/2022
but this format gives only date and i want to time with date. so i added time format in pattern like this.
1.
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss a");
2.
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss a").withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault());;
but it gives me following exception.
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
So how can i achieve "MM/dd/yyyy HH:mm:ss a"
pattern from "2022-02-01T20:32:00.000Z"
string date?