Here you can find the source of addDate(String date, String type, int into)
public static String addDate(String date, String type, int into) throws Exception
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { public static String addDate(String date, String type, int into) throws Exception { String Sdate = ""; try {/*from w w w. ja v a2 s . com*/ GregorianCalendar grc = new GregorianCalendar(); grc.setTime(new Date(date)); if (type.equals("D")) { grc.add(GregorianCalendar.DATE, into); } else if (type.equals("M")) { grc.add(GregorianCalendar.MONTH, into); } else if (type.equals("Y")) { grc.add(GregorianCalendar.YEAR, into); } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Sdate = new String(formatter.format(grc.getTime())); } catch (Exception e) { throw e; } return Sdate; } public static String addDate(String date, String into) throws Exception { String Sdate = ""; try { date = date.replaceAll("-", "/"); date = date.substring(0, date.length() - 2); GregorianCalendar grc = new GregorianCalendar(); grc.setTime(new Date(date)); grc.add(GregorianCalendar.DATE, Integer.parseInt(into)); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Sdate = new String(formatter.format(grc.getTime())); } catch (Exception e) { throw e; } return Sdate; } /** * Returns a string the represents the passed-in date parsed according to * the passed-in format. Returns an empty string if the date or the format * is null. **/ public static String format(Date aDate, SimpleDateFormat aFormat) { if (aDate == null || aFormat == null) { return ""; } synchronized (aFormat) { return aFormat.format(aDate); } } }