Java.util.GregorianCalendar.roll() 方法示例


Java.util.GregorianCalendar.roll() 方法示例

package com.codingdict;

import java.util.*;

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

      // create a new calendar
      GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

      // print the current date and time
      System.out.println("" + cal.getTime());

      // roll 2 months
      cal.roll(GregorianCalendar.MONTH, 2);
      System.out.println("Date:" + cal.getTime());

      // roll 5 year backwards
      cal.roll(GregorianCalendar.YEAR, -5);
      System.out.println("Date:" + cal.getTime());
   }
}