Java Utililty Methods Month of Year

List of utility methods to do Month of Year

Description

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

Method

StringgetNextiMonth(Date date, int month)
get Nexti Month
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
c.setTime(new Date());
c.add(Calendar.DATE, month);
Date d2 = c.getTime();
String s = df.format(d2);
return s;
DategetNextMonth()
get Next Month
String pattern = "yyyy-MM-dd";
Calendar cd = Calendar.getInstance();
cd.add(Calendar.MONTH, 1);
String newTime = String.valueOf(cd.get(Calendar.YEAR)) + "-" + String.valueOf(cd.get(Calendar.MONTH) + 1)
        + "-" + String.valueOf(cd.get(Calendar.DAY_OF_MONTH));
return convertStringToDate(newTime, pattern);
StringgetNextMonth(Calendar aCal)
get Next Month
DateFormat aFmt = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = (Calendar) aCal.clone();
cal.add(Calendar.MONTH, 1);
return aFmt.format(cal.getTime());
DategetNextMonth(Date nowdate, int delay)
get Next Month
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar temp = Calendar.getInstance();
temp.setTime(nowdate);
int oldMonth = temp.get(Calendar.MONTH);
int newMonth = oldMonth + delay;
int oldYear = temp.get(Calendar.YEAR);
int i, j;
if (newMonth > 12) {
...
StringgetNextMonthFirstDay(String date)
get Next Month First Day
Calendar cal = Calendar.getInstance();
Date dt = strToDtSimpleFormat(date);
cal.setTime(dt);
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DATE, 1);
return dateFormat(cal.getTime());
TgetNextMonthFirstDay(T day)
get Next Month First Day
if (day == null)
    return null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(day);
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month + 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
String datefor = format(calendar.getTime(), "yyyy-MM-dd");
...
StringgetNextMonthFistDay(String nowdate, String inFormat, String outFormat)
get Next Month Fist Day
Date date = getDateFromString(nowdate, inFormat);
Calendar cl = Calendar.getInstance();
cl.setTime(date);
cl.set(2, cl.get(2) + 1);
cl.set(5, 1);
date = cl.getTime();
return getFormatTimeString(date, outFormat);
StringgetNextYearMonth(String yearMonth)
get Next Year Month
SimpleDateFormat format = new SimpleDateFormat(year_month_pattern);
Calendar calendar = Calendar.getInstance();
try {
    calendar.setTime(format.parse(yearMonth));
} catch (ParseException e) {
    e.printStackTrace();
calendar.add(Calendar.MONTH, 1);
...
intgetNrDaysOfMonth(int month, int year)
get Nr Days Of Month
Calendar cal = calendarForFirstDayOf(month, year);
return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
intgetNumberOfDays(int year, int month)
Returns the number of days in the provided month and year.
Calendar calendar = new GregorianCalendar(year, month, 1);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);