Java Date Before getDateBefore(Date date, int days)

Here you can find the source of getDateBefore(Date date, int days)

Description

Get date before the input date according to param-days

License

Open Source License

Parameter

Parameter Description
date a parameter
days must be negtive

Return

Date

Declaration

public static Date getDateBefore(Date date, int days) 

Method Source Code

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

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//  w  w  w .  j a  va  2s  .c  o m
     * Get date before the input date according to param-days
     * 
     * @author Randy Wong
     * @param date
     * @param days
     *            must be negtive
     * @return Date
     */
    public static Date getDateBefore(Date date, int days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(java.util.Calendar.DAY_OF_YEAR, days);
        return calendar.getTime();
    }
}

Related

  1. getBeforeDate(String range)
  2. getBeforeHourByCurrentTime(Date now, int mount)
  3. getBeforeOrAfterDateByDayNumber(int dayNumber)
  4. getDateBefore(Date d, int day)
  5. getDateBefore(Date d, int day)
  6. getDateBefore(int offsetDay, String strFormat)
  7. getDateBefore(int year, int month, int day)
  8. getDateBefore(String d, int day)
  9. getDateBeforeHours(Date date, int hours)