Calendar class set(int year, int month, int date) method example
Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.
Calendar class set(int year, int month, int date)method example. This example shows you how to use set(int year, int month, int date)method.This method Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.
Here is the code:-
/**
* @Program that Sets the values for the calendar fields YEAR, MONTH,
* and DAY_OF_MONTH.
* Set2.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class Set2 {
public static void main(String[] args) {
Calendar c= Calendar.getInstance();
//Displays the current calendar
System.out.println("Calendar before Setting is "+c.getTime());
//Sets all the calendar field values and the time value of this Calendar
//undefined.
c.clear();
//Sets the values for the calendar fields YEAR, MONTH,and DAY_OF_MONTH.
c.set(2007,10,27);
//Displays the calendar after setting
System.out.println("Calendar after Setting is "+c.getTime());
}
} |
Output of the program:-
Calendar before Setting is Sat May 24 11:43:32 IST 2008
Calendar after Setting is Tue Nov 27 00:00:00 IST 2007 |
|