Java Day of getStartDate(int days, String strEndDate)

Here you can find the source of getStartDate(int days, String strEndDate)

Description

get Start Date

License

Apache License

Declaration

public static String getStartDate(int days, String strEndDate) 

Method Source Code

//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;
    }
}

Related

  1. getSpcilNumDayArray(Date startDate, int num)
  2. getSpecifiedDayAfter(String specifiedDay)
  3. getSpecifiedDayAfter(String specifiedDay, int afterDay)
  4. getSpecifiedDayTimeAfter(Date date)
  5. getStandardDayFormat(Date day)
  6. getStartDateByDays(Date endDate, int days)
  7. getStringAfterNDay(String str, int n)
  8. getStringDay(Calendar cal)
  9. getTargetDay(String day, int beforeOrAfterDays)