I have input date like April 17th, 2024
. Date was constructed by google speech to text service.
To format this date into different format I would use next code:
String input = "April 17th, 2024";
DateTimeFormatter f = DateTimeFormatter.ofPattern( "MMM d, uuuu" )
.withLocale( Locale.US );
ZonedDateTime zdt = ZonedDateTime.parse( input , f );
LocalDate ld = zdt.toLocalDate();
DateTimeFormatter fLocalDate = DateTimeFormatter.ofPattern( "dd/MM/uuuu" );
String output = ld.format( fLocalDate);
System.out.println(output);
...the issue is that input date should be April 17, 2024
or pattern have to be improved.
Very strict solution is to cut out letters after number.
I would prefer to avoid of adding additional logic and improve date pattern for input data. Exactly with this step I need help (I can't find correct solution in java doc).
So I hope to get formatter correction or confirmation, that java doesn't support standards where date can be 17th
, 3rd
and so on.