Java Utililty Methods Month Convert

List of utility methods to do Month Convert

Description

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

Method

intmonthNumber(String s)
returns 1,2,...,12 for the English month name.
if (s.length() < 3)
    throw new ParseException("need at least three letters", 0);
s = s.substring(0, 3);
for (int i = 0; i < 12; i++) {
    if (s.equalsIgnoreCase(mons[i]))
        return i + 1;
throw new ParseException("Unable to parse month", 0);
...
intmonthOfDate(Date s)
month Of Date
String d = FORMAT_YYYY_MM_DD.format(s);
return Integer.parseInt(d.substring(5, 7));
intmonthsBetween(String from, String to)
months Between method
return monthsBetween(from, to, "yyyyMMdd");
intmonthStringToInt(String month)
Converts a month title (like "December") into its equivalent number (12).
DateFormatSymbols df = new DateFormatSymbols();
int i = 0;
for (String mon : df.getMonths()) {
    if (mon.equalsIgnoreCase(month))
        return i + 1;
    i++;
return -1;
...
intnextMonth()
next Month
String next = format(new Date(), "M");
int nextMonth = Integer.parseInt(next) + 1;
if (nextMonth == 13)
    return 1;
return nextMonth;
DatenextMonth(Date date)
next Month
Calendar temp = Calendar.getInstance();
temp.setTime(date);
int y = temp.get(Calendar.YEAR);
int m = temp.get(Calendar.MONTH) + 1;
int d = temp.get(Calendar.DAY_OF_MONTH);
String sj1 = "";
if (d >= 1 && d <= 20) {
    d = 21;
...
DatenextMonth(Date date)
next Month
Calendar c = new GregorianCalendar();
c.setTime(date);
c.add(Calendar.MONTH, 1);
return c.getTime();
DateparseMonth(final String source)
Parse the Date using pattern "yyyy-MM"
if (source == null || source.trim().length() == 0) {
    return null;
return monthFormat.parse(source);
DatesetMonths(Date date, int amount)
Sets the months field to a date returning a new object.
return set(date, Calendar.MONTH, amount);