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.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date addDate(String date) { if (date == null) { return null; }//ww w . ja va 2s. co m Date tempDate = parseDate("yyyy-MM-dd", 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 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 = "yyyy-MM-dd HH:mm:ss"; } SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat); Date newDate = null; try { newDate = dateFormat.parse(dateValue); } catch (ParseException pe) { newDate = null; } return newDate; } public static String format(Date aTs_Datetime) { return format(aTs_Datetime, "yyyy-MM-dd"); } 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); } public static String getTime(Date date) { SimpleDateFormat formatter_f = new SimpleDateFormat("yyyy-MM-dd"); String str = formatter_f.format(date); return str; } }