Add 10 months to the calendar in Java
Description
The following code shows how to add 10 months to the calendar.
Example
/*from w ww .j av a 2s . c o m*/
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println("Today : " + cal.getTime());
// Substract 30 days from the calendar
cal.add(Calendar.DATE, -30);
System.out.println("30 days ago: " + cal.getTime());
}
}
The code above generates the following result.