Java Month Name Get getMonthNames(Locale locale)

Here you can find the source of getMonthNames(Locale locale)

Description

Get an array of month names for a given locale.

License

Open Source License

Parameter

Parameter Description
locale Locale

Return

String[]

Declaration

public static String[] getMonthNames(Locale locale) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2005 Will Roethel./*from   ww w . ja v a  2 s  .  co  m*/
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*    Will Roethel - initial API and implementation
*******************************************************************************/

import java.util.GregorianCalendar;
import java.util.Locale;
import java.text.SimpleDateFormat;

public class Main {
    /**
     * Get an array of month names for a given locale.
     * @param locale Locale
     * @return String[]
     */
    public static String[] getMonthNames(Locale locale) {
        // get a norm calendar using the default locale
        SimpleDateFormat monthFormatter = new SimpleDateFormat("MMMM", locale);
        String[] monthName = new String[12];
        GregorianCalendar cal = new GregorianCalendar(2005, java.util.Calendar.JANUARY, 1);
        for (int iMonth = 0; iMonth < 12; iMonth++) {
            monthName[iMonth] = monthFormatter.format(cal.getTime());
            cal.add(java.util.Calendar.MONTH, 1);
        }
        return monthName;
    }

    /**
     * Get an array with month names for the default locale.
     * @return String[]
     */
    public static String[] getMonthNames() {
        return getMonthNames(Locale.getDefault());
    }
}

Related

  1. getMonthName(int monthNumber)
  2. getMonthName(String code)
  3. getMonthName(String dateString)
  4. getMonthName(String month)
  5. getMonthNames(Locale locale)
  6. getMonthSelect(String selectName, String value, boolean hasBlank)
  7. getMonthStr(int month)
  8. getMonthStr(int month)
  9. getMonthStr(String str)