Java GregorianCalendar - getActualMaximum() Method
The java.util.GregorianCalendar.getActualMaximum() method returns the maximum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
For example, if the date of this instance is February 1, 2004, the actual maximum value of the DAY_OF_MONTH field is 29 because 2004 is a leap year, and if the date of this instance is February 1, 2005, it's 28.
Syntax
public int getActualMaximum(int field)
Parameters
field |
Specify the calendar field. |
Return Value
Returns the maximum of the given field for the time value of this GregorianCalendar.
Exception
NA
Example:
In the example below, the java.util.GregorianCalendar.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 GregorianCalendar 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(GregorianCalendar.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 GMT 2015 Actual Maximum for DAY_OF_MONTH: 28
❮ Java.util - GregorianCalendar