Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control the capitalization of month and day names returned by 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 ) );
}

The output is:

Months: en: September es: septiembre fr: septembre de: September Days: en: Monday 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.

like image 758
user9661 Avatar asked Sep 15 '08 20:09

user9661


1 Answers

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 on french capitalization

like image 142
brabster Avatar answered Oct 12 '22 00:10

brabster