如何控制 DateFormat 返回的月份和日期名称的大小写? [英] How to control the capitalization of month and day names returned by DateFormat?

查看:21
本文介绍了如何控制 DateFormat 返回的月份和日期名称的大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个快速测试程序:

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 关于法语大写

这篇关于如何控制 DateFormat 返回的月份和日期名称的大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆