Here you can find the source of getPreMonthDate(Date date, int month)
Parameter | Description |
---|---|
date | Date |
month | integer |
public static Date getPreMonthDate(Date date, int month)
//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(); } }