Java Date Time - Java Calendar.set(int field, int value)








Syntax

Calendar.set(int field, int value) has the following syntax.

public void set(int field, int value)

Example

In the following code shows how to use Calendar.set(int field, int value) method.

/*from   w w w .j a va2s.  co m*/

import java.util.Calendar;

public class Main {

   public static void main(String[] args) {

      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, 2013);

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

The code above generates the following result.