Here you can find the source of getDateBeforeOrAfterV2(int idx)
public static Date getDateBeforeOrAfterV2(int idx)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private final static String DATE_FORMAT = "yyyy-MM-dd"; public static Date getDateBeforeOrAfterV2(int idx) { return getDateBeforeOrAfter(getFormatDateToDate(getCurrDate()), idx); }/*w ww. j av a 2 s. c om*/ public static Date getDateBeforeOrAfter(int iDate) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, iDate); return cal.getTime(); } public static Date getDateBeforeOrAfter(Date curDate, int iDate) { Calendar cal = Calendar.getInstance(); cal.setTime(curDate); cal.add(Calendar.DAY_OF_MONTH, iDate); return cal.getTime(); } public static Date getFormatDateToDate(java.util.Date currDate) { return getFormatDate(getFormatDate(currDate)); } public static java.util.Date getCurrDate() { return new java.util.Date(); } public static String getFormatDate(java.util.Date currDate) { return getFormatDate(currDate, DATE_FORMAT); } public static Date getFormatDate(String currDate) { return getFormatDate(currDate, DATE_FORMAT); } public static String getFormatDate(java.util.Date currDate, String format) { SimpleDateFormat dtFormatdB = null; try { dtFormatdB = new SimpleDateFormat(format); return dtFormatdB.format(currDate); } catch (Exception e) { dtFormatdB = new SimpleDateFormat(DATE_FORMAT); try { return dtFormatdB.format(currDate); } catch (Exception ex) { } } return null; } public static Date getFormatDate(String currDate, String format) { SimpleDateFormat dtFormatdB = null; try { dtFormatdB = new SimpleDateFormat(format); return dtFormatdB.parse(currDate); } catch (Exception e) { dtFormatdB = new SimpleDateFormat(DATE_FORMAT); try { return dtFormatdB.parse(currDate); } catch (Exception ex) { } } return null; } }