Java Utility Library

Java Calendar - getMaximum() Method



The java.util.Calendar.getMaximum() method returns the maximum value for the given calendar field of this Calendar instance. The maximum value is defined as the largest value returned by the get method for any possible time value. The maximum value depends on calendar system specific parameters of the instance.

Syntax

public abstract int getMaximum(int field)

Parameters

field Specify the calendar field.

Return Value

Returns the maximum value for the given calendar field.

Exception

NA

Example:

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

import java.util.*;

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

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

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

    //printing the maximum value for year
    int yr = Cal.getMaximum(Calendar.YEAR);
    System.out.println("Maximum for YEAR: " + yr);
  }
}

The output of the above code will be:

The Calendar is: Wed Nov 25 00:00:00 UTC 2015
Maximum for DAY_OF_MONTH: 31
Maximum for YEAR: 292278994

❮ Java.util - Calendar