Java get month string from integer
Month
enum
You could use the Month
enum. This enum is defined as part of the new java.time framework built into Java 8 and later.
int monthNumber = 10;
Month.of(monthNumber).name();
The output would be:
OCTOBER
Localize
Localize to a language beyond English by calling getDisplayName
on the same Enum.
String output = Month.OCTOBER.getDisplayName ( TextStyle.FULL , Locale.CANADA_FRENCH );
output:
octobre
Try:
import java.text.DateFormatSymbols;
monthString = new DateFormatSymbols().getMonths()[month-1];
Alternatively, you could use SimpleDateFormat:
import java.text.SimpleDateFormat;
System.out.println(new SimpleDateFormat("MMMM").format(date));
(You'll have to put a date with your month in a Date
object to use the second option).