Java Month Name Get getMonth(String monthName)

Here you can find the source of getMonth(String monthName)

Description

Returns the index of month name provided.

License

Open Source License

Parameter

Parameter Description
monthName a parameter

Return

index of month

Declaration

public static int getMonth(String monthName) 

Method Source Code


//package com.java2s;

import java.text.DateFormatSymbols;

public class Main {
    /**/*from  ww  w .ja  v  a2  s .  c om*/
     * Returns the index of month name provided.
     * Indexes start from 0. i.e. January -> 0
     * @param monthName
     * @return index of month
     */
    public static int getMonth(String monthName) {
        String[] months = getMonths();
        int month = 0;
        for (int i = 0; i < months.length; i++) {
            if (monthName.equals(months[i])) {
                month = i;
            }
        }
        return month;
    }

    /**
     * Returns all months in a string array.
     * Indexes start from 0. i.e. 0 -> January
     * @return months
     */
    public static String[] getMonths() {
        return new DateFormatSymbols().getMonths();
    }
}

Related

  1. createDaemonThread(Runnable runnable, String threadName)
  2. getDutchMonthName(int monthNumber)
  3. getMonth(boolean name)
  4. getMonthByName(String monthName)
  5. getMonthFromMonthName(String name)
  6. getMonthName()
  7. getMonthName(Date date)