Given the following code
LocalDate localDateEpoch = LocalDate.parse(
"01-Jan-2017", DateTimeFormatter.ofPattern("d-MMM-yyyy", Locale.FRENCH));
System.out.println("localDateEpoch: " + localDateEpoch);
The reason why i picked french is – French numbers are latin so in theory it should just interpret this (Same with the letters in “Jan”). Nevertheless i got this error
Exception in thread "main" java.time.format.DateTimeParseException:
Text '01-Jan-2017' could not be parsed at index 3
My questions
- First: (Locale related) What’s up with the lack of countries/languages? They are very limited
- 2nd: (Locale related) Why are there locales for languages/countries (like
French
andFrance
)? - 3rd: What does this even do?
Now i’ve done a bit of research on my end.
Seems to resolve the lack of languages issues mentioned above you could just do Locale.forLanguageTag("fa");
but again why not have Locale.Iran/Persian
. Saw a post mentioning about how to convert numerical values to Persian in this case, so i tried to do the opposite.
LocalDate localDateEpoch = LocalDate.parse(
"۰۱-Jan-۲۰۱۷", DateTimeFormatter.ofPattern("d-MMM-yyyy", Locale.forLanguageTag("fa")));
And again i got an error.
Exception in thread "main" java.time.format.DateTimeParseException:
Text '۰۱-Jan-۲۰۱۷' could not be parsed at index 0
Also just if your curious i tried it without MMM
and still got the same error.