Java Utililty Methods Month Name Get

List of utility methods to do Month Name Get

Description

The list of methods to do Month Name Get are organized into topic(s).

Method

StringgetMonthStr(String str)
get Month Str
String[] monthOfYear = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV",
        "DEC" };
if ("01".equals(str)) {
    str = monthOfYear[0];
} else if ("02".equals(str)) {
    str = monthOfYear[1];
} else if ("03".equals(str)) {
    str = monthOfYear[2];
...
StringgetMonthString(int month)
get Month String
String monthString = "";
switch (month) {
case 1:
    monthString = "January";
    break;
case 2:
    monthString = "February";
    break;
...
StringgetPreMonthText(String pattern)
get Pre Month Text
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -1);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(c.getTime());
intmonth(String monthName)
Convert a month name (english names) (or a valid abbreviation) to an int in {1,12}.
for (int i = 0; i < months.length; i++) {
    String m = months[i];
    if (m.startsWith(monthName)) {
        return i + 1;
return -1;
intmonthCalValue(String monthName)
month Cal Value
if (monthName.compareToIgnoreCase("Jan") == 0 || monthName.compareToIgnoreCase("January") == 0)
    return Calendar.JANUARY;
if (monthName.compareToIgnoreCase("Feb") == 0 || monthName.compareToIgnoreCase("February") == 0)
    return Calendar.FEBRUARY;
if (monthName.compareToIgnoreCase("Mar") == 0 || monthName.compareToIgnoreCase("March") == 0)
    return Calendar.MARCH;
if (monthName.compareToIgnoreCase("Apr") == 0 || monthName.compareToIgnoreCase("April") == 0)
    return Calendar.APRIL;
...
StringmonthName(int month)
month Name
String monthName = "";
switch (month) {
case 1:
    monthName = "Janvier";
    break;
case 2:
    monthName = "Fevrier";
    break;
...
StringmonthName(int n)
month Name
switch (n) {
case 1:
    return "January";
case 2:
    return "February";
case 3:
    return "March";
case 4:
...
StringmonthNameAbbrev(int mon)
returns "jan", "feb", ..., "dec" for month number (1,2,...,12).
if (mon < 1 || mon > 12)
    throw new IllegalArgumentException("invalid month number: " + mon);
return mons[mon - 1];
StringtoMonthNameAbreviated(int m)
to Month Name Abreviated
if (m == 1)
    return "Jan";
if (m == 2)
    return "Fev";
if (m == 3)
    return "Mar";
if (m == 4)
    return "Abr";
...