tl;dr
LocalDate.now() // Better to specify time zone explicitly: LocalDate.now( ZoneId.of( "Pacific/Auckland" ) )
.getMonth // Get `Month` enum object appropriate to that date in that zone.
.getDisplayName( // Generate a `String`, the localized name of the month.
FormatStyle.FULL , // Control how long or how abbreviated the text.
Locale.CANADA_FRENCH // Specify the human language and cultural norms to be applied in localizing.
)
java.time
The Answer by posutes is correct.
The modern approach uses the java.time classes that supplanted the troublesome old legacy date-time classes (Date
, Calendar
, SimpleDateFormat
).
ZonedDateTime
replaces Calendar
, representing a moment on the timeline with the wall-clock time used by people of a certain region (a time zone), with a resolution of nanoseconds.
ZonedDateTime zdt = ZonedDateTime.now() ; // Would be better to pass explicitly the desired/expected time zone rather than implicitly rely on the JVM’s current default.
Retrieve a Month
enum object for the month of this ZonedDateTime
object’s date.
Month month = zdt.getMonth() ;
Generate a string for the name of the month, automatically localized. To localize, specify:
TextStyle
to determine how long or abbreviated should the string be.
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.
Ask for localized name of month.
Locale locale = Locale.US ; // Or Locale.CANADA_FRENCH etc.
String monthName = month.getDisplayName( FormatStyle.FULL , locale ) ;
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.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for 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.