One Two Three
One Two Three

Reputation: 23547

SimpleDateFormat and Locale API in Java

I have the following piece of code, which I thought would work as per what the documentation promised, but it didn't!

public static void main(String[] args) throws ParseException
{
    SimpleDateFormat fm = new SimpleDateFormat("yyyy/MMMM/dd",    // format str
                                               new Locale("gd",   // language = Scottish Gaelic
                                                          "UK",   // region   = UK
                                                          "scotland")); // variant = scotland
    fm.parse("2013/an Dàmhair/25");
}

Executing this (when it's put in a class with proper imports/declaration) will give the following error.

Exception in thread "main" java.text.ParseException: Unparseable date: "2013/an Dàmhair/25"
    at java.text.DateFormat.parse(DateFormat.java:357)
    at Foo.main(Foo.java:15)

Could anyone tell me if this is a bug (and/or unsupported feature)?

The date string is clearly valid date string in the Gaelic language, and the variant/language is also properly set. (Otherwise, I would expect to get IllegalArgument or some thing like that).

Any suggestion how to fix it would be greatly appreciated, too.

Thanks,

Upvotes: 0

Views: 323

Answers (2)

René Link
René Link

Reputation: 51483

You can define your own DateFormatSymbols

public static void main(String[] args) throws ParseException {
    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(new Locale("gd", "UK", "scotland"));
    // sorry I don't know the other months in Scottish Gaelic. Thus the numbers
    dateFormatSymbols.setMonths(new String[] { "1", "2", "3", "4", "5",
            "6", "7", "8", "9", "an Dàmhair", "11", "12" }); 

    SimpleDateFormat fm = new SimpleDateFormat("yyyy/MMMMM/dd", dateFormatSymbols); 
    System.out.println( fm.parse("2013/an Dàmhair/25"));
}

I hope this is a solution for you

Upvotes: 1

Arnaud Denoyelle
Arnaud Denoyelle

Reputation: 31283

According to this list, this locale is not supported.

Upvotes: 2

Related Questions