Here you can find the source of getStringAfterNDay(String str, int n)
public static String getStringAfterNDay(String str, int n)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getStringAfterNDay(String str, int n) { Calendar ca = parseStringToCalendar(str); if (ca == null) { return null; }/* w w w . j av a 2 s. c o m*/ ca.add(Calendar.DATE, n); String strDate = ca.get(Calendar.YEAR) + "-"; int intMonth = ca.get(Calendar.MONTH) + 1; if (intMonth < 10) { strDate += "0" + intMonth + "-"; } else { strDate += intMonth + "-"; } int intDay = ca.get(Calendar.DATE); if (intDay < 10) { strDate += "0" + intDay; } else { strDate += intDay; } return strDate; } public static Calendar parseStringToCalendar(String strDate) { java.util.Date date = parseStringToUtilDate(strDate); if (date == null) { return null; } Calendar ca = Calendar.getInstance(); ca.setTime(date); return ca; } public static java.util.Date parseStringToUtilDate(String strDate) { java.util.Date date = null; try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); date = df.parse(strDate); } catch (Exception ex) { ex.printStackTrace(); } return date; } }