Java Month Name Get getMonthNames(Locale locale)

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

Description

Returns a List of month name Strings - suitable for calendar headings.

License

Apache License

Parameter

Parameter Description
locale a parameter

Return

List of month name Strings

Declaration

public static List<String> getMonthNames(Locale locale) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import java.util.List;
import java.util.Locale;

public class Main {
    /**//from www .  j  av a 2s  .  co m
     * Returns a List of month name Strings - suitable for calendar headings.
     *
     * @param locale
     * @return List of month name Strings
     */
    public static List<String> getMonthNames(Locale locale) {
        Calendar tempCal = Calendar.getInstance(locale);
        tempCal.set(Calendar.MONTH, Calendar.JANUARY);
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale);
        List<String> resultList = new ArrayList<String>();
        for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) {
            resultList.add(dateFormat.format(tempCal.getTime()));
            tempCal.roll(Calendar.MONTH, 1);
        }
        return resultList;
    }
}

Related

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