Java Utililty Methods Month Add

List of utility methods to do Month Add

Description

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

Method

DateaddMonth(Date date, int month)
add Month
Date retDate = (Date) date.clone();
retDate.setMonth(retDate.getMonth() + month);
return retDate;
DateaddMonth(Date date, int month)
Addiert einen Monat.
final Calendar cal = getCalendarInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, month);
final Date result = cal.getTime();
return result;
DateaddMonth(Date date, int months)
add Month
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, months);
return cal.getTime();
DateaddMonths(Date date, int iMonthCount)
add Months
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, iMonthCount);
return calendar.getTime();
DateaddMonths(Date date, int months)
Add specified number of months to the date given.
if (months == 0)
    return date;
if (date == null)
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, months);
return cal.getTime();
...
StringaddMonths(int updateInterval, String dateFormat)
Add months to todays date and return as string
if (updateInterval == -1)
    return "Exempt";
SimpleDateFormat timeFormat = new SimpleDateFormat(dateFormat);
Calendar tCalendar = Calendar.getInstance();
Date tDate = new Date();
Integer year = Integer.parseInt(new SimpleDateFormat(separateDate(dateFormat, "y")).format(tDate)); 
Integer month = Integer.parseInt(new SimpleDateFormat(separateDate(dateFormat, "M")).format(tDate)) - 1;
Integer day = Integer.parseInt(new SimpleDateFormat(separateDate(dateFormat, "d")).format(tDate)); 
...
java.util.DateaddMonths(java.util.Date today, int monthsToAdd)
addMonths: returns date + given months
if (today != null) {
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.setTime(today);
    c.add(Calendar.MONTH, monthsToAdd);
    return c.getTime();
} else {
    return null;
StringaddMonths(String s, int month)
add Months
return addMonths(s, month, "yyyyMMdd");
StringaddMonths2(String dateStr, int months)
add Months
Date date = getStrDateToDate(dateStr);
date = addMonths(date, months);
date = addDays(date, -1);
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("yyyy" + getDateSplit() + "MM" + getDateSplit() + "dd");
String dateString = formatter.format(date);
return dateString.trim();
DateaddMonthsAndDays(Date date, int months, int days)
add Months And Days
Calendar sysDate = new GregorianCalendar();
sysDate.setTime(date);
sysDate.add(Calendar.MONTH, months);
sysDate.add(Calendar.DAY_OF_MONTH, days);
return sysDate.getTime();