Reading direction
Your format pattern string , MMM YYYY dd
, says that the month abbreviation comes first, then year, then day of month. It’s impossible to tell from the look, but when I copy-paste your date string, 18 ??? 2010
, then day of month (18) comes first, then the month abbreviation (??? for October) and then finally the year (2010). Since Hebrew is read right to left and the rest left to right, the string looks the same in both cases. And since the order really does not agree behind the scenes, parsing fails.
So the solutions are two (at least):
Fix your date string to match the format pattern.
Fix your format pattern to match the date string:
DateTimeFormatter f = DateTimeFormat.forPattern("dd MMM YYYY")
.withLocale(Locale.forLanguageTag("iw-IL"));
In the latter case output from your code is (in my time zone):
Mon Oct 18 00:00:00 CEST 2010
It doesn’t work readily on all Java versions
… but this doesnt work on java-11. But it works on java-8
That’s because the default locale data have changed in Java 9. Until Java 8 Java’s own locale data were used as the default. From Java 9 CLDR (Unicode Common Locale Date Repository) is the default. Here the Hebrew abbreviation for October is ????. For how to make parsing of the string you have got work on Java 9, 11 and later, see JDK dateformatter parsing DayOfWeek in German locale, java8 vs java9.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…