Java Month Number Get getMonthDigit(String month)

Here you can find the source of getMonthDigit(String month)

Description

get Month Digit

License

Apache License

Declaration

public static String getMonthDigit(String month) 

Method Source Code

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

public class Main {
    /**/*from ww w  . j a v a  2 s .co  m*/
     * This method returns the numeric value in string so that further it can be
     * concanated with other value strings like day,hours,min,seconds at the
     * time of getting eraseTime at savingTransaction.
     * 
     * @param month -
     *            String values like "Jan","Feb"....etc.
     * @return String
     */
    private static String[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
            "Nov", "Dec" };

    public static String getMonthDigit(String month) {
        if ("123456789101112".indexOf(month) != -1) {
            return month;
        }
        String mon = "-1";
        for (int i = 0; i < 12; i++) {
            if (equalsIgnoreCase(month, monthNames[i])) {
                mon = "" + (i + 1);
                break;
            }
        }
        return mon;
    }

    public static boolean equalsIgnoreCase(String str1, String str2) {
        if (str1 == null && str2 == null) {
            return true;
        }
        if ((str1 == null && str2 != null) || (str1 != null && str2 == null)) {
            return false;
        }
        if (str1.toLowerCase().equals(str2.toLowerCase())) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. eemonth(double serial_number)
  2. getInitialsByMonthNumber(String monthNumber)
  3. getMonthIds()
  4. getMonthIndex(String str)
  5. getMonthIndexAsString(String type)
  6. getMonthNumberByMonthInitials(String monthInitials)