How do I Get a List of Month Names?

Category: java.text, viewed: 5947 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.

package org.kodejava.example.text;

import java.text.DateFormatSymbols;
import java.util.Locale;

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);
        }

        String[] germanyMonths = new DateFormatSymbols(Locale.GERMANY).getMonths();
        for (int i = 0; i < germanyMonths.length; i++) {
            String germanyMonth = germanyMonths[i];
            System.out.println("germanyMonth = " + germanyMonth);
        }

        String[] germanyShortMonths = new DateFormatSymbols(Locale.GERMANY).getShortMonths();
        for (int i = 0; i < germanyShortMonths.length; i++) {
            String germanyShortMonth = germanyShortMonths[i];
            System.out.println("germanyShortMonth = " + germanyShortMonth);
        }
    }
}

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
month = 
shortMonth = Jan
shortMonth = Feb
shortMonth = Mar
shortMonth = Apr
shortMonth = May
shortMonth = Jun
shortMonth = Jul
shortMonth = Aug
shortMonth = Sep
shortMonth = Oct
shortMonth = Nov
shortMonth = Dec
shortMonth = 
germanyMonth = Januar
germanyMonth = Februar
germanyMonth = März
germanyMonth = April
germanyMonth = Mai
germanyMonth = Juni
germanyMonth = Juli
germanyMonth = August
germanyMonth = September
germanyMonth = Oktober
germanyMonth = November
germanyMonth = Dezember
germanyMonth = 
germanyShortMonth = Jan
germanyShortMonth = Feb
germanyShortMonth = Mrz
germanyShortMonth = Apr
germanyShortMonth = Mai
germanyShortMonth = Jun
germanyShortMonth = Jul
germanyShortMonth = Aug
germanyShortMonth = Sep
germanyShortMonth = Okt
germanyShortMonth = Nov
germanyShortMonth = Dez
germanyShortMonth = 
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats