Java Date to Month getNextMonthExtention(Date dt, Long n)

Here you can find the source of getNextMonthExtention(Date dt, Long n)

Description

get Next Month Extention

License

Apache License

Declaration

public static Date getNextMonthExtention(Date dt, Long n) 

Method Source Code

//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();
        }
    }
}

Related

  1. getMonthStartDay(Date date)
  2. getNextMonth(Date baseDate, int Month)
  3. getNextMonth(Date time)
  4. getNextMonth(long date)
  5. getNextMonthDate(Date appointDate)
  6. getNextMonthFirstDate(Date date)
  7. getNextMonthFirstDay(Date date)
  8. getNextMonthPreviousDay(Date date, int month_num)
  9. getNextMonthsByStartDate(Date date, int month)