.getActualMaximum()
Anonymous contributor
Published Aug 22, 2023
Contribute to Docs
The .getActualMaximum()
method of the Calendar
class returns the actual maximum value for a specific calendar field based on the current state of the calendar instance.
Syntax
calendar.getActualMaximum(int field)
This method takes only one argument, int field
, which is an integer constant representing the calendar field for which the maximum value will be returned. The value is based on factors such as the given day, month or year (e.g. Calendar.MONTH
).
Example
In the following example, .getActualMaximum()
is used to retrieve the maximum value of both the Calendar.MONTH
and Calendar.YEAR
fields. This example will return the maximum day in the month of February of the year 2012.
import java.util.Calendar;// CalendarMaxExample.javapublic class CalendarMaxExample {public static void main(String[] args) {// Create a Calendar instanceCalendar calendar = Calendar.getInstance();// Set the year field to 2012calendar.set(Calendar.YEAR, 2012);// Set the month field to Februarycalendar.set(Calendar.MONTH, Calendar.FEBRUARY);// Retrieve the actual maximum day in February of the year 2012int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// Print the resultSystem.out.println("Maximum day of the month: " + maxDay);}}
The output of the above code will be 29 implying that 2012 was a leap year:
Maximum day of the month: 29
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.