Java Date Before getDateBefore(String d, int day)

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

Description

get Date Before

License

Apache License

Declaration

public static String getDateBefore(String d, int day) 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {

    public static String getDateBefore(String d, int day) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        Calendar now = Calendar.getInstance();
        try {//ww  w.  j  a v  a2 s.c om
            now.setTime(format.parse(d));
            now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return format.format(now.getTime());
    }
}

Related

  1. getDateBefore(Date d, int day)
  2. getDateBefore(Date d, int day)
  3. getDateBefore(Date date, int days)
  4. getDateBefore(int offsetDay, String strFormat)
  5. getDateBefore(int year, int month, int day)
  6. getDateBeforeHours(Date date, int hours)
  7. getDateBeforeNextMonth(Date date, Integer month, Integer day)
  8. getDateBeforeOrAfter(int iDate)
  9. getDateBeforeOrAfterV2(int idx)