Java Year Month AddMonths(int yearMonth, int interval)

Here you can find the source of AddMonths(int yearMonth, int interval)

Description

Add Months

License

Open Source License

Declaration

public static int AddMonths(int yearMonth, int interval) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {

    public static int AddMonths(int yearMonth, int interval) throws Exception {
        int result = 0;
        java.util.Date ym;//from ww w  .  j av a2  s .  co m

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        ym = sdf.parse(String.valueOf(yearMonth));

        Calendar cal = Calendar.getInstance();
        cal.setTime(ym);
        cal.add(Calendar.MONTH, interval);

        result = Integer.parseInt(sdf.format(cal.getTime()));

        return result;
    }
}

Related

  1. addDate(Calendar cal, int year, int month, int day)
  2. calculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour, int incrementMin, int incrementSec)
  3. createCalendar(int year, int month, int date, int hour, int minute, int second)
  4. createDate(final int year, final int month, final int day, final int hour, final int minutes, final int seconds, final int miliseconds)
  5. createDate(int year, int month, int day)