Java Date Before getMonthBefore(Date currentDate, int numberMonthBefore)

Here you can find the source of getMonthBefore(Date currentDate, int numberMonthBefore)

Description

get Month Before

License

Open Source License

Declaration

@SuppressWarnings("deprecation")
    public static Date getMonthBefore(Date currentDate, int numberMonthBefore) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    @SuppressWarnings("deprecation")
    public static Date getMonthBefore(Date currentDate, int numberMonthBefore) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, currentDate.getYear() + 1900);
        calendar.set(Calendar.MONTH, currentDate.getMonth() + 1 - numberMonthBefore);
        calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
        return calendar.getTime();
    }/*from  w  w w. ja v  a 2  s.c o  m*/
}

Related

  1. getDayBeforeOrAfter2(Date time, int days)
  2. getDayFormSomeDay(Date date, int n, boolean before)
  3. getDistanceMonthOfTwoDate(Date before, Date after)
  4. getMinuteBefore(Date date, int minute)
  5. getMonth(Date time, int monthBefore, int monthAfter)
  6. getMonthStartDateBeforeCurrent(int monthNum, Date current)
  7. getOneHourBefore(Date date)
  8. getPassedMonthBetweenDate(Date before, Date after)
  9. getPreviousDate(String before)