2. 42. 4. Increment and Decrement Months Using the Calendar Class
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println("Now : " + cal.getTime());
int monthsToDecrement = -1;
cal.add(Calendar.MONTH, monthsToDecrement);
System.out.println("Date after decrement: " + cal.getTime());
}
}
/*Now : Wed Feb 18 13:52:43 PST 2009
Date after decrement: Sun Jan 18 13:52:43 PST 2009
*/