Java Month Calculate nextMonths(int diff)

Here you can find the source of nextMonths(int diff)

Description

next Months

License

Apache License

Declaration

public static Date nextMonths(int diff) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static Date nextMonths(int diff) {
        return add(new Date(), Calendar.MONTH, diff);
    }//  w  w w  .  java2s. c  o  m

    public static Date nextMonths(Date date, int diff) {
        return add(date, Calendar.MONTH, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(Date date, int field, int diff) {
        Calendar c = getCalendar(date);
        c.add(field, diff);
        return c.getTime();
    }

    /**
     * @since 2008-01-02
     */
    public static Date add(int field, int diff) {
        return add(new Date(), field, diff);
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(long millis) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(millis);
        return c;
    }

    /**
     * @since 2008-01-02
     */
    public static Calendar getCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
}

Related

  1. isFirstOfMonth(long date)
  2. isMonthEnd(Date date)
  3. isSameMonth(final Calendar c1, final Calendar c2)
  4. monthsBetween(String pFormerStr, String pLatterStr)
  5. nextMonth(Date date, int months)
  6. startOfMonth(Date d)
  7. startOfMonth(Date date)
  8. startOfMonthDate(Date date)
  9. truncateMonth(Date d)