Java Calendar.add Method Guide

In Java, the add method of the Calendar class is used to increase or decrease the value of a specified field. The usage of this method is as follows:

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1); // 增加一个月
calendar.add(Calendar.DAY_OF_MONTH, -7); // 减少7天

In the example above, a Calendar instance was first created, and then the add method was used to increase a month and decrease 7 days respectively. It should be noted that the first parameter indicates the field to increase or decrease, and the second parameter indicates the amount to add or subtract, with negative numbers indicating subtraction and positive numbers indicating addition. The Calendar class provides some constants to represent different fields, such as Calendar.MONTH for months, Calendar.DAY_OF_MONTH for dates, and so on.

bannerAds