Calendar class set(int field, int value)method example
Sets the given calendar field to the given value.
Calendar class set(int field, int value)method example. This example shows you how to use set(int field, int value)method.This method Sets the given calendar field to the given value.
Here is the code:-
/**
* @Program that Sets the given calendar field to the given value
* Set1.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class Set1 {
public static void main(String[] args) {
Calendar c= Calendar.getInstance();
System.out.println("Year before Setting is "+c.get(Calendar.YEAR));
//Sets the given calendar field to the given value i.e=2007
c.set(Calendar.YEAR, 2007);
System.out.print("Year after Setting is "+c.get(Calendar.YEAR));
}
} |
Output of the program:-
Year before Setting is 2008
Year after Setting is 2007 |
|