Home »
Java programming language
Java GregorianCalendar getActualMaximum() Method with Example
GregorianCalendar Class getActualMaximum() method: Here, we are going to learn about the getActualMaximum() method of GregorianCalendar Class with its syntax and example.
Submitted by Preeti Jain, on February 15, 2020
GregorianCalendar Class getActualMaximum() method
- getActualMaximum() method is available in java.util package.
- getActualMaximum() method is used to get the actual maximum value that this GregorianCalendar field (fi) can hold.
- getActualMaximum() method is a non-static method, it is accessible with class object only and if we try to access the method with class name then we will get an error.
- getActualMaximum() method does not throw an exception at the time of returning maximum value that the given field can hold.
Syntax:
public int getActualMaximum(int fi);
Parameter(s):
- int fi – represents the GregorianCalendar field (fi).
Return value:
The return type of this method is int, it returns actual maximum value of the given field (fi).
Example:
// Java program to demonstrate the example
// of int getActualMaximum(int fi) method of
// GregorianCalendar
import java.util.*;
public class GetActualMaximumOfGregorianCalendar {
public static void main(String[] args) {
// Instantiating a GregorianCalendar object
GregorianCalendar ca = (GregorianCalendar) GregorianCalendar.getInstance();
// Display current GregorianCalendar
System.out.println("ca: " + ca.getTime());
// By using getActualMaximum() method is to
// return the maximum value of the given field
// that can hold
int year = ca.getActualMaximum(GregorianCalendar.YEAR);
int month = ca.getActualMaximum(GregorianCalendar.MONTH);
int day = ca.getActualMaximum(GregorianCalendar.DATE);
// Display Maximum value of GregorianCalendar Fields
System.out.println("ca.getActualMaximum(GregorianCalendar.YEAR): " + year);
System.out.println("ca.getActualMaximum(GregorianCalendar.MONTH): " + month);
System.out.println("ca.getActualMaximum(GregorianCalendar.DATE): " + day);
}
}
Output
ca: Sat Feb 15 08:33:22 GMT 2020
ca.getActualMaximum(GregorianCalendar.YEAR): 292278994
ca.getActualMaximum(GregorianCalendar.MONTH): 11
ca.getActualMaximum(GregorianCalendar.DATE): 29