0

我有以下代码,我认为它可以按照文档的承诺工作,但事实并非如此!

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");
}

执行此操作(当它放入具有正确导入/声明的类中时)将产生以下错误。

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)

谁能告诉我这是否是一个错误(和/或不受支持的功能)?

日期字符串在盖尔语中显然是有效的日期字符串,并且变体/语言也已正确设置。(否则,我希望得到 IllegalArgument 或类似的东西)。

任何如何解决它的建议也将不胜感激。

谢谢,

4

2 回答 2

2

根据此列表,不支持此语言环境。

于 2013-10-28T14:41:05.360 回答
1

您可以定义自己的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"));
}

我希望这是你的解决方案

于 2013-10-28T14:41:12.720 回答