Java Date Previous getPreMonthDate(Date date, int month)

Here you can find the source of getPreMonthDate(Date date, int month)

Description

get the previos n month

License

Open Source License

Parameter

Parameter Description
date Date
month integer

Return

Date

Declaration

public static Date getPreMonthDate(Date date, int month) 

Method Source Code

//package com.java2s;
/*//from   ww w  . j a  va  2  s.c  om
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

public class Main {
    /**
     * get the previos n month
     *
     * @param date Date
     * @param month integer
     * @return Date
     */
    public static Date getPreMonthDate(Date date, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - month, calendar.get(Calendar.DATE),
                0, // hour
                0, // min
                0); // sec
        /**
         * clear millisecond field
         */
        calendar.clear(Calendar.MILLISECOND);
        return calendar.getTime();

    }
}

Related

  1. getPreDay(Date date)
  2. getPrefixStartDate(Integer day)
  3. GetPreMonthBeginDate()
  4. getPrevDay(Date date)
  5. getPrevDueDate(int payperiod, long time)
  6. getPreviousDate(Date date)
  7. getPreviousDate(final Date date)