Java Month Next nextMonth(Date date, int month)

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

Description

get the next n month.

License

Open Source License

Parameter

Parameter Description
date Date
month number of next month

Return

Date

Declaration

public static Date nextMonth(Date date, int month) 

Method Source Code

//package com.java2s;
/*/*from  www . j a v  a  2  s.c o m*/
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * get the next n month.
     *
     * @param date Date
     * @param month number of next month
     * @return Date
     */
    public static Date nextMonth(Date date, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + month, calendar.get(Calendar.DATE),
                0, // hour
                0, // min
                0); // sec
        /**
         * clear millisecond field
         */
        calendar.clear(Calendar.MILLISECOND);
        return calendar.getTime();
    }
}

Related

  1. nextMonth(Date d)
  2. nextMonth(Date date)
  3. nextMonth(Date then)
  4. nextMonth(final Date date)
  5. nextMonthDateTime(Date date, int month)
  6. nextMonthStart(Date period)