Java日历Calendar roll方法


Java日历Calendar roll方法

package com.codingdict;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar
      Calendar cal = Calendar.getInstance();

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

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

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

      // roll downwards
      cal.roll(Calendar.MONTH, -4);

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