Java Calendar.get(int field)

Syntax

Calendar.get(int field) has the following syntax.

public int get(int field)

Example

In the following code shows how to use Calendar.get(int field) method.


/*w  w w.ja  v a  2s .  c o  m*/


import java.util.Calendar;

public class Main {

   public static void main(String[] args) {
      
      Calendar cal = Calendar.getInstance();

      // get the value of all the calendar date fields.
      System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR));
      System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH));
      System.out.println("Calendar's Day: " + cal.get(Calendar.DATE));
   }
}

The code above generates the following result.