Java Calendar set方法


Java Calendar set方法

package com.codingdict;

import java.util.Calendar;

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

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

      // print current year
      System.out.println("Current year is :" + cal.get(Calendar.YEAR));

      // set the year to something else
      cal.set(Calendar.YEAR, 1997);

      // print the result
      System.out.println("Altered year is :" + cal.get(Calendar.YEAR));
   }
}