Here you can find the source of getBeforeOrAfterDate(String strDate, int months)
public static String getBeforeOrAfterDate(String strDate, int months)
//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); } }