Java Month Add addMonth(Date date, int month)

Here you can find the source of addMonth(Date date, int month)

Description

add Month

License

Open Source License

Declaration

@SuppressWarnings("deprecation")
public static Date addMonth(Date date, int month) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    @SuppressWarnings("deprecation")
    public static Date addMonth(Date date, int month) {
        Date retDate = (Date) date.clone();
        retDate.setMonth(retDate.getMonth() + month);
        return retDate;

    }//from ww w  .j ava 2 s .  c  om

    public static int getMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int month = cal.get(Calendar.MONTH);
        return (month + 1);
    }
}

Related

  1. addMonth(Date date, int month)
  2. addMonth(Date date, int months)
  3. addMonths(Date date, int iMonthCount)
  4. addMonths(Date date, int months)