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) throws Exception 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static Date getDateBefore(Date d, int day) throws Exception {
        Calendar now = Calendar.getInstance();
        now.setTime(d);// w  w  w  .j  av  a2  s  .  c  o m
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(simpleDateFormat.format(now.getTime()));
        return date;
    }
}

Related

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