Here you can find the source of getNextMonthExtention(Date dt, Long n)
public static Date getNextMonthExtention(Date dt, Long n)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date getNextMonthExtention(Date dt, Long n) { Calendar cal = new GregorianCalendar(); cal.setTime(dt);// ww w . j ava 2 s . c o m Calendar firstCal = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(), 1); if (firstCal.getActualMaximum(Calendar.DAY_OF_MONTH) < cal.get(Calendar.DAY_OF_MONTH)) { return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue() + 1, 1) .getTime(); } else { return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(), cal.get(Calendar.DAY_OF_MONTH)).getTime(); } } }