How can I convert an Integer to localized month name in Java?

atomsfat picture atomsfat · Jun 24, 2009 · Viewed 139.1k times · Source

I get an integer and I need to convert to a month names in various locales:

Example for locale en-us:
1 -> January
2 -> February

Example for locale es-mx:
1 -> Enero
2 -> Febrero

Answer

joe picture joe · Jun 24, 2009
import java.text.DateFormatSymbols;
public String getMonth(int month) {
    return new DateFormatSymbols().getMonths()[month-1];
}