Java Month Get getBeforeOrAfterDate(String strDate, int months)

Here you can find the source of getBeforeOrAfterDate(String strDate, int months)

Description

get Before Or After Date

License

Apache License

Declaration

public static String getBeforeOrAfterDate(String strDate, int months) 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

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

public class Main {
    private static final Object[] Date = null;

    public static String getBeforeOrAfterDate(String strDate, int months) {

        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;//from ww  w  . jav a  2 s. co  m
        try {
            date = df2.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, months);
        Date otherDate = cal.getTime();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd ");

        return dateFormat.format(otherDate);
    }
}

Related

  1. currentMonth()
  2. currentMonthStr()
  3. getAktMonthName()
  4. getAllMonths(String date1, String date2)
  5. getBeforeMonth(int amount)
  6. getCurMonth2Long()
  7. getCurrMonthLastDay()
  8. getEndDateOfMonth(String yyyymmdd)
  9. getEngMonth()