Here you can find the source of addMonths(Date date, int months)
Parameter | Description |
---|---|
date | Date |
months | Int number of months to add |
public static Date addMonths(Date date, int months)
//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(); } }