How do I Get a List of Month Names?

Bookmark this example!  
Category: java.text, viewed: 1320 time(s).

The example code below helps you to get all month names as an array of String. The first method, getMonths() return the full name string while the second method getShortMonths() return the short name of the month.

 
import java.text.DateFormatSymbols;
 
public class MonthNames
{
    public static void main(String[] args)
    {
        String[] months = new DateFormatSymbols().getMonths();
        for (int i = 0; i < months.length; i++)
        {
            String month = months[i];
            System.out.println("month = " + month);
        }
 
        String[] shortMonths = new DateFormatSymbols().getShortMonths();
        for (int i = 0; i < shortMonths.length; i++)
        {
            String shortMonth = shortMonths[i];
            System.out.println("shortMonth = " + shortMonth);
        }
    }
}
 
 

The result of the code above are:

month = January
month = February
month = March
month = April
month = May
month = June
month = July
month = August
month = September
month = October
month = November
month = December

shortMonth = Jan
shortMonth = Feb
shortMonth = Mar
shortMonth = Apr
shortMonth = May
shortMonth = Jun
shortMonth = Jul
shortMonth = Aug
shortMonth = Sep
shortMonth = Oct
shortMonth = Nov
shortMonth = Dec
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats