Java Utililty Methods Month Get

List of utility methods to do Month Get

Description

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

Method

StringgetMonthString(int month)

Returns string representation of a given month in the year

Calendar cal = new GregorianCalendar(2002, month, 1);
SimpleDateFormat formatter = new SimpleDateFormat("MMMM");
return (formatter.format(cal.getTime()));
StringgetMonthStringFromNumber(String monthNumber)
get Month String From Number
int monthInt = -1;
try {
    monthInt = Integer.parseInt(monthNumber);
} catch (NumberFormatException e) {
    return "";
if (monthInt < 1 || monthInt > 12) {
    return "";
...
String[]getMonthStrings()
DateFormatSymbols returns an extra, empty value at the end of the array of months.
String[] months = new java.text.DateFormatSymbols().getMonths();
int lastIndex = months.length - 1;
if ((months[lastIndex] == null) || (months[lastIndex].length() <= 0)) {
    String[] monthStrings = new String[lastIndex];
    System.arraycopy(months, 0, monthStrings, 0, lastIndex);
    return monthStrings;
} else {
    return months;
...
StringgetNearbyMonth(String month, int i)
get Nearby Month
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
Date mydate = formatter.parse(month);
Calendar calendar = Calendar.getInstance();
calendar.setTime(mydate);
calendar.add(Calendar.MONTH, i);
return formatter.format(calendar.getTime());
StringgetReportMonthString()
get Report Month String
DateFormatSymbols dfs = new DateFormatSymbols(new Locale("ro"));
String[] months = dfs.getMonths();
if (Calendar.getInstance().get(Calendar.MONTH) > 0) {
    return months[Calendar.getInstance().get(Calendar.MONTH) - 1];
} else {
    return months[11];
DategetSelectMonth(String month)
get Select Month
SimpleDateFormat sdf;
Date time = new Date();
sdf = new SimpleDateFormat("yyyy");
String date = sdf.format(time);
date = date + "-" + month + "-01 00:00:00.0";
sdf.applyPattern("yyyy-MM");
Date curDate = null;
try {
...
StringgetShortMonthForInt(final Locale locale, int theMonth)
get Short Month For Int
String month = "???";
DateFormatSymbols dfs = new DateFormatSymbols(locale);
String[] months = dfs.getShortMonths();
month = months[theMonth % 12];
return month;
DategetSpecficMonthStart(Date date, int amount)
get Specfic Month Start
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, amount);
cal.set(Calendar.DAY_OF_MONTH, 1);
return getStartDate(cal.getTime());
DategetStartDateOfMonth(String yyyymm)
get Start Date Of Month
SimpleDateFormat sformat = new SimpleDateFormat("yyyy-MM-dd");
try {
    return sformat.parse(yyyymm + "-01");
} catch (Exception e) {
    throw new RuntimeException(e);
StringgetStrOfNextMonth(String dateStr)
get Str Of Next Month
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
    Date date = sdf.parse(dateStr);
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return sdf.format(getDateOfNextMonth(c).getTime());
} catch (ParseException e) {
    throw new IllegalArgumentException("Invalid date format(yyyy-MM-dd): " + dateStr);
...