Mridang Agarwalla Mridang Agarwalla - 4 months ago 11
Android Question

Unable to parse a date in the Finnish locale

I'm trying to parse a Finnish date using the examples I've found here on Stack Overflow but I keep getting a parsing exception.

Here's my snippet:

SimpleDateFormat dftFormat = new SimpleDateFormat("dd MMMM yyyy", new Locale("fi", "FI"));
Date datDate = dftFormat.parse("25 syyskuu 2012");


The
DateFormat
characters seem to the same as the one in English so i'm wondering why this doesn't work.

Here's the information about the Finnish locale.

Thanks.

Answer

It seems that all Finnish dates end with a ta i.e. syyskuu becomes syyskuuta.

The locale reference that I gave was wrong. If you see that link, you'll notice that the ta is missing and that was some misleading information. I couldn't find the exact locale information for the Finnish locale in the Javadocs.

I learnt a lesson, thanks to @Eis and @Fildor, print out the date using your parsing format to see what the resultant string is. Then you can compare whether your input string is parseable using the format.

Here's how I tested my code:

Date datDate = dftFormat.parse("25 syyskuuta 2012");
System.out.println(new SimpleDateFormat("dd MMMM yyyy").format(datDate));
Comments