如何控制DateFormat返回的月份和日期名称的大小写? [英] How to control the capitalization of month and day names returned by DateFormat?
本文介绍了如何控制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 ) );
}
输出是:
月份:
en:September
es:septiembre
fr:septembre
de:September
Days:
en:星期一
es:lunes
fr:lundi
de:Montag
我可以控制名称的大小写吗?由于某种原因,西班牙语和法语总是似乎返回以小写字母开头的名称。
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...
这篇关于如何控制DateFormat返回的月份和日期名称的大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文