Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

To increment or decrement a field of a calendar by 1 using the roll() method

By +1 or -1, depending on the second argument(true or false). import java.util.Calendar; import java.util.GregorianCalendar; public class MainClass {   public static void main(String[] a) {     GregorianCalendar calendar = new GregorianCalendar();     calendar.roll(Calendar.MONTH, false); // Go back a month     System.out.println(calendar.get(Calendar.MONTH));   } } 11