Java Date Before getDateBefore(int year, int month, int day)

Here you can find the source of getDateBefore(int year, int month, int day)

Description

get Date Before

License

Open Source License

Declaration

public static Date getDateBefore(int year, int month, int day) 

Method Source Code

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

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

public class Main {
    public static Date getDateBefore(int year, int month, int day) {
        Date result = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(result);/*w w  w  .j  a  v a 2 s  . com*/
        calendar.add(Calendar.YEAR, year);
        calendar.add(Calendar.MONTH, month);
        calendar.add(Calendar.DAY_OF_MONTH, day);
        result = calendar.getTime();
        return result;
    }

    public static Date getDateBefore(Date date, int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR, year);
        calendar.add(Calendar.MONTH, month);
        calendar.add(Calendar.DAY_OF_MONTH, day);
        date = calendar.getTime();
        return date;
    }
}

Related

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