Java.util.Calendar.getActualMaximum() Method



Description

The java.util.Calendar.getActualMaximum() method returns the maximum value that the specified calendar field could have, based on the time value of this Calendar.

Declaration

Following is the declaration for java.util.Calendar.getActualMaximum() method

public int getActualMaximum(int field)

Parameters

  • field − the given calendar field.

Return Value

Returns the maximum of the given calendar field.

Exception

NA

Example

The following example shows the usage of java.util.calendar.getActualMaximum() method.

package com.tutorialspoint;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar
      Calendar cal = Calendar.getInstance();

      // get the maximum value that year field can have
      int i = cal.getActualMaximum(Calendar.YEAR);
      System.out.println("Maximum year:" + i);

      // get the maximum value that month field can have
      int a = cal.getActualMaximum(Calendar.MONTH);
      System.out.println("Maximum month:" + a);
   }
}

Let us compile and run the above program, this will produce the following result −

Maximum year:292278994
Maximum month:11
java_util_calendar.htm
Advertisements