Here you can find the source of getMonthIndex(String str)
Parameter | Description |
---|---|
str | a string which (should be) a month |
private static int getMonthIndex(String str)
//package com.java2s; //License from project: Open Source License public class Main { private static final String strMonths[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /**// w w w .j a v a 2 s . c o m * simple little function to get the index of the month. * compare just the first three letters to avoid confusion with * misspellings and whether or not abreviations have a period. * also allow for 1 based indexs * @param str a string which (should be) a month * @return one based index */ private static int getMonthIndex(String str) { int ix; int iValue; if (str == null || str.length() == 0) return (-1); str = str.trim(); if (str.length() > 3) str = str.substring(0, 3); for (ix = 0; ix < strMonths.length; ++ix) { if (str.equalsIgnoreCase(strMonths[ix].substring(0, 3))) return (ix); } // if the month value does not match one of the three letter // abreviations it may be the 1 based index of the month try { iValue = Integer.parseInt(str); } catch (NumberFormatException nfe) { return (-1); } while (iValue < 1) iValue += 12; while (iValue > 12) iValue -= 12; return (iValue - 1); } }