tl;dr
convert a long value to … date … month written out
Instant.ofEpochMilli( myMillis )
.atZone( ZoneId.of( "Pacfic/Auckland" ) )
.getMonth()
.getDisplayName( TextStyle.FULL , Locale.ITALY ) // Or Locale.US, Locale.UK, etc.
ottobre
Avoid legacy date-time classes
The other Answers use the troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
java.time
Assuming your long
value represents a count of milliseconds since the first moment of 1970 in UTC, use Instant
.
The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
Instant instant = Instant.ofEpochMilli( myMillis ) ;
You want a month written out. Determining a month means determining a date. Determining a date requires a time zone. 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( "Africa/Tunis" );
ZonedDateTime zdt = instant.atZone( z ) ; // Same moment in history, but adjusted into the wall-clock time of a particular region of people.
Now interrogate for the month. The java.time classes include a Month
enum, to represent a month January-December.
Month m = zdt.getMonth() ;
The Month
enum includes handy methods such as generating a String in an automatically localized format.
String output = m.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH ) ; // Or Locale.US, Locale.ITALY, etc.
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.
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.