如何控制 DateFormat 返回的月份和日期名称的大小写?

2022-01-18 00:00:00 date internationalization java

这是一个快速测试程序:

Here is a quick test program:

    public static void main( String[] args )
{
    Date date = Calendar.getInstance().getTime();

    System.out.println("Months:");
    printDate( "MMMM", "en", date );
    printDate( "MMMM", "es", date );
    printDate( "MMMM", "fr", date );
    printDate( "MMMM", "de", date );

    System.out.println("Days:");
    printDate( "EEEE", "en", date );
    printDate( "EEEE", "es", date );
    printDate( "EEEE", "fr", date );
    printDate( "EEEE", "de", date );

}

public static void printDate( String format, String locale, Date date )
{
    System.out.println( locale + ": " + (new SimpleDateFormat( format, new Locale( locale ) )).format( date ) );
}

输出是:

<代码>月份:zh: 九月es: 九月法国:九月去:九月天:zh: 星期一es: 月牙fr: 隆迪de: 蒙塔格

如何控制名称的大小写.出于某种原因,西班牙语和法语似乎总是返回以小写字母开头的名称.

How can I control the capitalization of the names. For some reason the Spanish and French always seem to return names that start with a lowercase letter.

推荐答案

并非所有语言都共享英文大写规则.我猜您需要更改 API 使用的数据,但您的非英语客户可能不喜欢它...

Not all languages share english capitalization rules. I guess you'd need to alter the data used by the API, but your non-english clients might not appreciate it...

about.com 关于法语大写

相关文章