Java Date Time - Java Calendar.set(int year, int month, int date)








Syntax

Calendar.set(int year, int month, int date) has the following syntax.

public final void set(int year, int month, int date)

Example

In the following code shows how to use Calendar.set(int year, int month, int date) method.

/*w  ww .j  a va  2 s .c  o  m*/


import java.util.Calendar;

public class Main {

   public static void main(String[] args) {

      Calendar cal = Calendar.getInstance();

      // print current time
      System.out.println("Current year is :" + cal.getTime());

      // set the year,month and day to something else
      cal.set(2013, 5, 25);

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

The code above generates the following result.