Java Date Before getDateBefore(Date d, int day)

Here you can find the source of getDateBefore(Date d, int day)

Description

get Date Before

License

Apache License

Declaration

public static Date getDateBefore(Date d, int day) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static Date getDateBefore(Date d, int day) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);/* w  w w .j a va 2s. c  o  m*/
        now.set(Calendar.HOUR_OF_DAY, 0);
        now.set(Calendar.MINUTE, 0);
        now.set(Calendar.SECOND, 0);
        now.set(Calendar.MILLISECOND, 0);
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        return now.getTime();
    }
}

Related

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