Java Date Time - Java Calendar.roll(int field, boolean up)








Syntax

Calendar.roll(int field, boolean up) has the following syntax.

public abstract void roll(int field, boolean up)

Example

In the following code shows how to use Calendar.roll(int field, boolean up) method.

/*from  w  w w  .  jav a  2 s  .  com*/


import java.util.Calendar;

public class Main {

   public static void main(String[] args) {

      Calendar cal = Calendar.getInstance();

      // displays the current calendar
      System.out.println("Month is " + cal.get(Calendar.MONTH));

      // roll month
      cal.roll(Calendar.MONTH, true);

      // print result after rolling
      System.out.println("Month is " + cal.get(Calendar.MONTH));

      // roll downwards
      cal.roll(Calendar.MONTH, false);

      // print result after rolling down
      System.out.println("Month is " + cal.get(Calendar.MONTH));
   }
}

The code above generates the following result.