Java Calendar getActualMaximum() Method



Description

The Java 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

Getting Maximum Year from a Calendar Instance Example

The following example shows the usage of Java Calendar getActualMaximum() method. We're creating a Calendar instance of current date. We're printing the maximum possible value of Year.

package com.tutorialspoint;

import java.util.Calendar;

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
      System.out.println("Maximum year:" + cal.getActualMaximum(Calendar.YEAR));
   }
}

Output

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

Maximum year:292278993

Getting Maximum Month from a Calendar Instance Example

The following example shows the usage of Java Calendar getActualMaximum() method. We're creating a Calendar instance of current date. We're printing the maximum possible value of Month.

package com.tutorialspoint;

import java.util.Calendar;

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

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

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

Output

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

Maximum month:11

Getting Maximum Day from a Calendar Instance Example

The following example shows the usage of Java Calendar getActualMaximum() method. We're creating a Calendar instance of current date. We're printing the maximum possible value of Day.

package com.tutorialspoint;

import java.util.Calendar;

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

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

      // get the maximum value that day field can have
      System.out.println("Maximum day:" + cal.getActualMaximum(Calendar.DAY_OF_MONTH));
   }
}

Output

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

Maximum day:30
java_util_calendar.htm
Advertisements