java DateTimeFormatterBuilder fails on testtime [duplicate]

The month name is in English, so you'd better set a java.util.Locale in the formatter.

If you don't set it, the formatter will use the JVM default locale. And if it's not English, you might get an error (and different environments might have different configurations, so it's better to set the locale instead of relying on the JVM's default).

Just do toFormatter(Locale.ENGLISH) instead of just toFormatter() and that's it.


You are using hh which is clock-hour-of-am-pm (1-12) without adding the AM/PM information in the date string.

Instead you should use of hour-of-day (0-23) like the pattern: DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z");

Or you can add the a in the date pattern:
DateTimeFormatter.ofPattern("dd/MMM/yyyy:hh:mm:ss a Z");

and pass the AM/PM information in the date string:

"20/Mar/2019:00:00:01 AM +0100"


EDIT:

As per the comments, the issue could also be with the locale you are using, in order to use the en/US locale just pass the locale to the ofPattern method:

 Locale locale = new Locale("en", "US");
 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z", locale); 

But you still need to correct the clock-hour-of-am-pm (hh) to hour-of-day (HH).