java.util.Calendar getMaximum(int field)
Description :
This java tutorial shows how to use the getMaximum(int field) method of Calendar class of java.util package. This method returns the maximum value for the given calendar field of this Calendar instance. The maximum value is defined as the highest value returned by the get method for any possible time value.
Method Syntax :
public abstract int getMaximum(int field)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
int | field | the calendar field we want to get the maximum value |
Method Returns :
This method returns int which corresponds to the maximum value for the given calendar field.
Compatibility Version :
Requires Java 1.1 and up
Exception :
N/A
Java Code Example :
This java example source code demonstrates the use of getMaximum(int field) method of Calendar class. This example java code simply prints the maximum values for some of the Calendar fields.
package com.javatutorialhq.java.examples; import java.util.Calendar; /* * This example source code demonstrates the use of * getMaximum(int field) of Calendar class */ public class CalendarGetMaximumExample { public static void main(String[] args){ Calendar cal = Calendar.getInstance(); System.out.println("Time:" + cal.getTime()); int maxYear = cal.getMaximum(Calendar.YEAR); int maxMonth = cal.getMaximum(Calendar.MONTH); int maxWeek = cal.getMaximum(Calendar.WEEK_OF_YEAR); int maxDate = cal.getMaximum(Calendar.DATE); System.out.println("Maximum Year:"+maxYear); System.out.println("Maximum Month:"+maxMonth); System.out.println("Maximum Week of Year:"+maxWeek); System.out.println("Maximum Date:"+maxDate); } }
Sample Output :
Running the getMaximum(int field) method example source code of Calendar class will give you the following output:
Exception Scenario :
N/A
Similar Method :
- N/A
Suggested Reading List :
References :