Java Date Time - 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 ww  .  j  a v a 2  s.  com


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.