The get(int field_value) method of Calendar class is used to return the value of the given calendar field in the parameter.
Syntax:
public int get(int field)
Parameters: The method takes one parameter field_value of integer type and refers to the calendar whose value is needed to be returned.
Return Value: The method returns the value of the passed field.
Below programs illustrate the working of get() Method of Calendar class:
Example 1:
// Java Code to illustrate // get() Method import java.util.*; public class CalendarClassDemo extends GregorianCalendar { public static void main(String args[]) { // Creating a calendar Calendar calndr = Calendar.getInstance(); // Getting the value of all // the calendar date fields System.out.println("The given calendar's" + " year is: " + calndr.get(Calendar.YEAR)); System.out.println("The given calendar's" + " month is: " + calndr.get(Calendar.MONTH)); System.out.println("The given calendar's" + " day is: " + calndr.get(Calendar.DATE)); } } |
The given calendar's year is: 2019 The given calendar's month is: 1 The given calendar's day is: 13
Example 2:
// Java Code to illustrate // get() Method import java.util.*; public class CalendarClassDemo extends GregorianCalendar { public static void main(String args[]) { // Creating a calendar object Calendar calndr = new GregorianCalendar(2018, 9, 2); // Getting the value of all // the calendar date fields System.out.println("The given calendar's" + " year is: " + calndr.get(Calendar.YEAR)); System.out.println("The given calendar's" + " month is: " + calndr.get(Calendar.MONTH)); System.out.println("The given calendar's" + " day is: " + calndr.get(Calendar.DATE)); } } |
The given calendar's year is: 2019 The given calendar's month is: 9 The given calendar's day is: 2
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#get(int)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Calendar set() Method in Java with Examples
- Calendar add() Method in Java with Examples
- Calendar getActualMaximum() Method in Java with Examples
- Calendar getGreatestMinimum() Method in Java with Examples
- Calendar getActualMinimum() Method in Java with Examples
- Calendar setTime() Method in Java with Examples
- Calendar getAvailableLocales() Method in Java with Examples
- Calendar getFirstDayOfWeek() Method in Java with Examples
- Calendar getDisplayNames() Method in Java with Examples
- Calendar getDisplayName() Method in Java with Examples
- Calendar computeFields() method in Java with Examples
- Calendar clear() Method in Java with Examples
- Calendar toString() Method in Java with Examples
- Calendar compareTo() Method in Java with Examples
- Calendar setTimeZone() Method in Java with Examples
- Calendar setTimeInMillis() Method in Java with Examples
- Calendar complete() Method in Java with Examples
- Calendar computeTime() method in Java with Examples
- Calendar clone() Method in Java with Examples
- Calendar roll() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

