Calendar class set(int year, int month, int date, int hourOfDay, int minute, int second) method example
Sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND.
Calendar class set(int year, int month, int date, int hourOfDay, int minute, int second)method example. This example shows you how to use set(int year, int month, int date, int hourOfDay, int minute, int second)method.This method Sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND.
Here is the code:-
/*
* @Program that Sets the values for the fields YEAR, MONTH, DAY_OF_MONTH,
HOUR, MINUTE, and SECOND.
* Set4.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class Set4 {
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 fields YEAR, MONTH, DAY_OF_MONTH,
//HOUR, MINUTE, and SECOND.
c.set(2007,10,27,14,35,9);
//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:54:04 IST 2008
Calendar after Setting is Tue Nov 27 14:35:09 IST 2007 |
|