Java Month Add addMonths(Date date, int months)

Here you can find the source of addMonths(Date date, int months)

Description

Add specified number of months to the date given.

License

Open Source License

Parameter

Parameter Description
date Date
months Int number of months to add

Return

Date

Declaration

public static Date addMonths(Date date, int months) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from w  w  w .j  ava2s .c o  m
     * Add specified number of months to the date given.
     * 
     * @param date
     *            Date
     * @param months
     *            Int number of months to add
     * @return Date
     */
    public static Date addMonths(Date date, int months) {
        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();
    }
}

Related

  1. addMonth(Date date, int month)
  2. addMonth(Date date, int month)
  3. addMonth(Date date, int months)
  4. addMonths(Date date, int iMonthCount)
  5. addMonths(int updateInterval, String dateFormat)
  6. addMonths(java.util.Date today, int monthsToAdd)
  7. addMonths(String s, int month)
  8. addMonths2(String dateStr, int months)