如何控制 DateFormat 返回的月份和日期名称的大小写?
2022-09-03 00:16:27
这是一个快速测试程序:
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 ) );
}
输出为:
Months:
en: September
es: septiembre
fr: septembre
de: September
Days:
en: Monday
es: lunes
fr: lundi
de: Montag
如何控制名称的大小写。由于某种原因,西班牙语和法语似乎总是返回以小写字母开头的名称。