Here you can find the source of getStartDate(int days, String strEndDate)
public static String getStartDate(int days, String strEndDate)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/* w ww. j a v a 2s. com*/ * yyyy-MM-dd HH:mm:ss */ public static final String STRING_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static String getStartDate(int days, String strEndDate) { Calendar endCal = Calendar.getInstance(); Date endDate = stringToDate(strEndDate, STRING_DATE_FORMAT); endCal.setTime(endDate); endCal.add(Calendar.DATE, -days); SimpleDateFormat sdf = new SimpleDateFormat(STRING_DATE_FORMAT); return sdf.format(endCal.getTime()); } /** * Convert string to Date * * @return a java.util.Date object converted. */ public static Date stringToDate(String pstrValue, String pstrDateFormat) { if ((pstrValue == null) || (pstrValue.equals(""))) { return null; } Date dttDate = null; try { SimpleDateFormat oFormatter = new SimpleDateFormat(pstrDateFormat); dttDate = oFormatter.parse(pstrValue); oFormatter = null; } catch (Exception e) { return null; } return dttDate; } }