Here you can find the source of getNDayAfterCurrentDate(String dateStr, String dateFormat, int n)
public static String getNDayAfterCurrentDate(String dateStr, String dateFormat, int n)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getNDayAfterCurrentDate(String dateStr, String dateFormat, int n) { try {//from w w w . j a va 2 s.c o m Calendar c = Calendar.getInstance(); Date date = parse(dateStr, dateFormat); c.setTime(date); c.add(c.DAY_OF_MONTH, n); return c.get(c.YEAR) + "-" + (c.get(c.MONTH) + 1) + "-" + c.get(c.DATE); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } } public static Date parse(String strDate, String pattern) throws ParseException { try { return getFormatter(pattern).parse(strDate); } catch (ParseException pe) { throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.", pe.getErrorOffset()); } } private static SimpleDateFormat getFormatter(String parttern) { return new SimpleDateFormat(parttern); } }