Calendar class get(int field) method example
Calendar class get(int field)method example. This example shows you how to use get(int field) method.This method Returns the value of the given calendar field.
Here is the code:-
/**
* @Program that Returns the value of the given calendar field.
* getcalender.java
* Author:-RoseIndia Team
* Date:-22-May-2008
*/
import java.util.*;
public class getcalender {
public static void main(String[] args) {
//Creating a calender
Calendar cal = Calendar.getInstance() ;
// Returns the value of the current calendar field.
System.out.println("Year: " + cal.get(Calendar.YEAR));
System.out.println("Month: " + cal.get(Calendar.MONTH));
System.out.println("Day: " + cal.get(Calendar.DATE));
}
} |
Output of the program:-
Year: 2008
Month: 4
Day: 22 |
|