tl;dr
How can I control the capitalization of the names
You don’t. Different languages and different cultures have different rules about capitalization, punctuation, abbreviation, etc.
getDisplayName
— automatically localize
Month.from( LocalDate.now( ZoneId.of( "Pacific/Auckland" ) ) ) // Get current month.
.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) // Localize automatically. Specify `Locale` to determine human language and cultural norms for translation.
février
LocalDate.now( ZoneId.of( "Pacific/Auckland" ) ) // Get current date as seen by people in a certain region (time zone).
.getDayOfWeek() // Get the day-of-week as a pre-defined `DayOfWeek` enum object.
.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH )
lundi
Localize
As others stated, you should not be forcing your own parochial (US English?) notions of capitalization. Use a decent date-time library, and let it automatically localize for you.
java.time
You are using terrible old date-time classes that are now legacy, supplanted by the java.time classes.
The LocalDate
class represents a date-only value without time-of-day and without time zone.
A time zone is crucial in determining a date. For any given moment, the date varies around the globe by zone. For example, a few minutes after midnight in Paris France is a new day while still “yesterday” in Montréal Québec.
Specify a proper time zone name in the format of continent/region
, such as America/Montreal
, Africa/Casablanca
, or Pacific/Auckland
. Never use the 3-4 letter abbreviation such as EST
or IST
as they are not true time zones, not standardized, and not even unique(!).
ZoneId z = ZoneId.of( "Asia/Kolkata" );
LocalDate today = LocalDate.now( z );
To work with a month, extract a Month
enum object. Ditto for day-of-week, DayOfWeek
.
Call getDisplayName
. Pass a TextStyle
for abbreviation. Pass a Locale
to determine (a) the human language for translation of name of day, name of month, and such, and (b) the cultural norms deciding issues of abbreviation, capitalization, punctuation, separators, and such. Note that Locale
has nothing to do with time zone.
Month m = today.getMonth() ;
String mNameQuébec = m.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) ;
String mNameGermany = m.getDisplayName( TextStyle.FULL , Locale.GERMANY ) ;
…and…
DayOfWeek dow = today.getDayOfWeek() ;
String dowNameQuébec = dow.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) ;
String dowNameGermany = dow.getDisplayName( TextStyle.FULL , Locale.GERMANY ) ;
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
With a JDBC driver complying with JDBC 4.2 or later, you may exchange java.time objects directly with your database. No need for strings or java.sql.* classes.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.