I would recommend using the Calendar and Locale object, as the names of the months are different for different languages:
// index can be 0 - 11 private String getMonthName(final int index, final Locale locale, final boolean shortName) { String format = "%tB"; if (shortName) format = "%tb"; Calendar calendar = Calendar.getInstance(locale); calendar.set(Calendar.MONTH, index); calendar.set(Calendar.DAY_OF_MONTH, 1); return String.format(locale, format, calendar); }
Example for the full name of the month:
System.out.println(getMonthName(0, Locale.US, false));
Result: January
Example for a short month name:
System.out.println(getMonthName(0, Locale.US, true));
Result: Jan
Sa Qada May 31 '17 at 12:52 2017-05-31 12:52
source share