Java Utility Library

Java Calendar - getActualMaximum() Method



The java.util.Calendar.getActualMaximum() method returns the maximum value that the specified calendar field could have, given the time value of this Calendar. For example, the actual maximum value of the MONTH field is 12 in some years, and 13 in other years in the Hebrew calendar system.

Syntax

public int getActualMaximum(int field)

Parameters

field Specify the calendar field.

Return Value

Returns the maximum of the given calendar field for the time value of this Calendar.

Exception

NA

Example:

In the example below, the java.util.Calendar.getActualMaximum() method returns the maximum value for the given field for the given time.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Calendar object with specified date
    Calendar Cal = new GregorianCalendar(2015, 1, 25);

    //printing the Calendar
    System.out.println("The Calendar is: " + Cal.getTime());

    //printing the actual maximum value for day_of_month
    int mon = Cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    System.out.println("Actual Maximum for DAY_OF_MONTH: " + mon);
  }
}

The output of the above code will be:

The Calendar is: Wed Feb 25 00:00:00 UTC 2015
Actual Maximum for DAY_OF_MONTH: 28

❮ Java.util - Calendar