Java Month Format getAfterByNMonth(String format, int months)

Here you can find the source of getAfterByNMonth(String format, int months)

Description

get After By N Month

License

Open Source License

Declaration

public static String getAfterByNMonth(String format, int months) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.Locale;

public class Main {
    public final static String DisplayDateFormat = "yyyy-MM-dd";

    public static String getAfterByNMonth(String format, int months) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, months);
        Date newDate = c.getTime();

        return formatDate(newDate, format);
    }//  w w w .j av  a  2 s .c  om

    public static String formatDate(Date date, String format) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    public static String formatDate(Date date) {
        return formatDate(date, DisplayDateFormat);
    }
}

Related

  1. formatMonth(int month)
  2. formatMonth(int month, Locale locale, boolean longFormat)
  3. formatMonth(String dateOrign)
  4. formatMonthDay(int decimal)
  5. formatMonthlyPeriod(String month)
  6. getCurrMonthFirstDaySlashFormat()
  7. getDisplayMonth(Date time, int monthBefore, int monthAfter, SimpleDateFormat format)
  8. getFirstDayOfNextMonth(String dateFormat)
  9. getFormatCurMonthAsYYYYMM()