Calendar internalGet() Method in Java with Examples

The internalGet(int calndr_field) method in Calendar class is used to return the value of the given calendar field as a parameter.
Note: The operation does not involve any normalization or validation.

Syntax:

protected final int internalGet(int calndr_field)

Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be operated upon.

Return Value: The method returns the value of the passed parameter.

Below programs illustrate the working of internalGet() Method of Calendar class:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// internalGet() method
  
import java.util.*;
  
public class CalendarDemo
    extends GregorianCalendar {
    public static void main(String args[])
    {
  
        // Creating a new calendar
        CalendarDemo calndr = new CalendarDemo();
  
        // Displaying the Current date
        System.out.println("The current date is: "
                           + calndr.getTime());
  
        // Getting the Month
        System.out.println("Month is: "
                           + calndr
                                 .internalGet(MONTH));
  
        // Getting the Year
        System.out.println("Year is: "
                           + calndr
                                 .internalGet(YEAR));
    }
}

chevron_right


Output:

The current date is: Wed Feb 20 16:11:36 UTC 2019
Month is: 1
Year is: 2019

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// internalGet() method
  
import java.util.*;
  
public class Calendar_Demo
    extends GregorianCalendar {
    public static void main(String args[])
    {
        // Creating a calendar object
        Calendar_Demo calndr = new Calendar_Demo();
  
        // Displaying the current date
        System.out.println("Calendar: "
                           + calndr
                                 .getTime());
  
        // Displaying the year
        System.out.println("Year: "
                           + calndr
                                 .internalGet(YEAR));
  
        // Displaying the month
        System.out.println("Month: "
                           + calndr
                                 .internalGet(MONTH));
  
        // Displaying other credentials
        System.out.println("Day: "
                           + calndr
                                 .internalGet(DAY_OF_WEEK));
    }
}

chevron_right


Output:

Calendar: Thu Feb 21 09:43:53 UTC 2019
Year: 2019
Month: 1
Day: 5

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#internalGet-int-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.