Here you can find the source of addDate(String date)
public static Date addDate(String date)
//package com.java2s; //License from project: Apache License import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static final String C_TIME_PATTON_DEFAULT = "yyyy-MM-dd HH:mm:ss"; public static final String C_DATE_PATTON_DEFAULT = "yyyy-MM-dd"; public static Date addDate(String date) { if (date == null) { return null; }//w ww . java 2 s . c om Date tempDate = parseDate(C_DATE_PATTON_DEFAULT, date); String year = format(tempDate, "yyyy"); String month = format(tempDate, "MM"); String day = format(tempDate, "dd"); GregorianCalendar calendar = new GregorianCalendar( Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); calendar.add(GregorianCalendar.DATE, 1); return calendar.getTime(); } /** * Parse a string and return a date value * * @param dateValue * @return * @throws Exception */ public static Date parseDate(String dateValue) { return parseDate(C_DATE_PATTON_DEFAULT, dateValue); } /** * Parse a string and return the date value in the specified format * * @param strFormat * @param dateValue * @return * @throws ParseException * @throws Exception */ public static Date parseDate(String strFormat, String dateValue) { if (dateValue == null) return null; if (strFormat == null) strFormat = C_TIME_PATTON_DEFAULT; SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat); Date newDate = null; try { newDate = dateFormat.parse(dateValue); } catch (ParseException pe) { pe.printStackTrace(); newDate = null; } return newDate; } public static String format(Date aTs_Datetime) { return format(aTs_Datetime, C_DATE_PATTON_DEFAULT); } public static String format(Date aTs_Datetime, String as_Pattern) { if (aTs_Datetime == null || as_Pattern == null) return null; SimpleDateFormat dateFromat = new SimpleDateFormat(); dateFromat.applyPattern(as_Pattern); return dateFromat.format(aTs_Datetime); } /** * @param aTs_Datetime * @param as_Pattern * @return */ public static String format(Timestamp aTs_Datetime, String as_Pattern) { if (aTs_Datetime == null || as_Pattern == null) return null; SimpleDateFormat dateFromat = new SimpleDateFormat(); dateFromat.applyPattern(as_Pattern); return dateFromat.format(aTs_Datetime); } }