Here you can find the source of addDate(String date, int amount)
public static Date addDate(String date, int amount)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date addDate(String date, int amount) { if (date == null || "".equals(date.trim())) { return null; }//from w w w . j av a 2 s .c o m Calendar calendar = Calendar.getInstance(); calendar.setTime(getDate(date)); calendar.add(Calendar.DATE, amount); return calendar.getTime(); } public static Date getDate(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(sdf.format(date)); } catch (ParseException e) { return null; } } public static Date getDate(Date date, String dateFormat) { SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); try { return sdf.parse(sdf.format(date)); } catch (ParseException e) { return null; } } public static Date getDate(String date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(date); } catch (ParseException e) { return null; } } public static Date getDate(String date, String dateFormat) { SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); try { return sdf.parse(date); } catch (ParseException e) { return null; } } public static Date add(Date d, int field, int amount) { if (d == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(d); calendar.add(field, amount); return calendar.getTime(); } public static Date getTime(String date) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.parse(date); } }