Java Day of getStartDateByDays(Date endDate, int days)

Here you can find the source of getStartDateByDays(Date endDate, int days)

Description

get Start Date By Days

License

Open Source License

Declaration

public static Date getStartDateByDays(Date endDate, int days) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String DF_YMD = "yyyy-MM-dd";
    public static final String DF_HMS = "HH:mm:ss";

    public static Date getStartDateByDays(Date endDate, int days) {
        Calendar calendarEndDate = Calendar.getInstance();
        calendarEndDate.setTime(endDate);
        calendarEndDate.add(Calendar.DAY_OF_YEAR, 0 - days);

        return calendarEndDate.getTime();
    }//from w w  w.  j  a va2 s  .  c o  m

    public static String getTime() {
        return dateToString(now(), DF_HMS);
    }

    public static String getTime(Date trialTime) {
        return dateToString(trialTime, DF_HMS);
    }

    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        }
        synchronized (date) {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.format(date);
        }
    }

    public static String dateToString(Date date) {
        return dateToString(date, DF_YMD);
    }

    public static Date now() {
        return new Date();
    }
}

Related

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