Java Calendar Month subtractMonths(Calendar date, int months)

Here you can find the source of subtractMonths(Calendar date, int months)

Description

Subtracts a given number of months from a date.

License

Open Source License

Parameter

Parameter Description
date The starting date
months The number of months to subtract

Return

A java.util.Calendar object with the result

Declaration

public static Calendar subtractMonths(Calendar date, int months) 

Method Source Code

//package com.java2s;
/*/*  www  . j  a  v a 2  s. c  om*/
   Animal Shelter Manager
   Copyright(c)2000-2011, R. Rawson-Tetley
    
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.
    
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston
   MA 02111-1307, USA.
    
   Contact me by electronic mail: bobintetley@users.sourceforge.net
*/

import java.util.Calendar;

public class Main {
    /**
     * Subtracts a given number of months from a date.
     * @param date The starting date
     * @param months The number of months to subtract
     * @return A java.util.Calendar object with the result
     */
    public static Calendar subtractMonths(Calendar date, int months) {
        date.add(Calendar.MONTH, (int) months * -1);

        return date;
    }
}

Related

  1. sameMonth(Calendar one, Calendar two)
  2. setDate(Calendar cal, int month, int date)
  3. setDate(Calendar cal, int month, int date, boolean endOfDay)
  4. setDate(Calendar calendar, int month, int date)
  5. setTimeAsFirstDayOfMonth(Calendar calendar)