GregorianCalendar getGreatestMinimum() Method in Java
The java.util.GregorianCalendar.getGreatestMinimum() method is an in-built function in Java which returns the highest minimum value for a calendar field, passed as parameter to the function, of this GregorianCalendar instance. The highest minimum value for any possible time value is defined as the smallest value returned by the get method with the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods, all taken into consideration.
Syntax:
public int getGreatestMinimum(int calendarfield)
Parameters: This function accepts one mandatory parameter calendarfield of integer type whose highest minimum value will be returned by the function.
Return Value: This method returns an integer which denotes the highest minimum value for the specified calendar field.
Examples:
Input : DAY_OF_MONTH Output : 1 Input : WEEK_OF_MONTH Output : 0
Below programs illustrate the working of java.util.GregorianCalendar.getGreatestMaximum() function:
Program 1:
// Java Program to illustrate getGreatestMinimum() import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { // Create a new calendar GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // Display the current date and time System.out.println("Current Date and Time : " + cal.getTime()); // Greatest minimum for WEEK_OF_MONTH int minm = cal.getGreatestMinimum( GregorianCalendar.WEEK_OF_MONTH); System.out.println("Greatest Minimum for"+ " WEEK_OF_MONTH field :" + minm); // Get greatest minimum for DAY_OF_MONTH minm = cal.getGreatestMinimum( GregorianCalendar.DAY_OF_MONTH); System.out.println("Greatest Minimum for" +" DAY_OF_MONTH field:" + minm); } } |
Current Date and Time : Wed Aug 01 07:21:14 UTC 2018 Greatest Minimum for WEEK_OF_MONTH field :0 Greatest Minimum for DAY_OF_MONTH field:1
Program 2:
// Java Program to illustrate getGreatestMinimum() import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { // Create a new calendar GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); // Display the current date and time System.out.println("Current Date and Time : " + cal.getTime()); // Get greatest minimum for YEAR int minm = cal.getGreatestMinimum (GregorianCalendar.YEAR); System.out.println("Greatest Minimum for"+ " YEAR field :" + minm); // Get greatest minimum for HOUR_OF_DAY minm = cal.getGreatestMinimum( GregorianCalendar.HOUR_OF_DAY); System.out.println("Greatest Minimum for"+ " HOUR_OF_DAY field:" + minm); } } |
Current Date and Time : Wed Aug 01 07:21:16 UTC 2018 Greatest Minimum for YEAR field :1 Greatest Minimum for HOUR_OF_DAY field:0
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#getGreatestMinimum()
Recommended Posts:
- Calendar getGreatestMinimum() Method in Java with Examples
- GregorianCalendar add() Method in Java
- GregorianCalendar hashCode() Method in Java
- GregorianCalendar getTimeZone() Method in Java
- GregorianCalendar clone() Method in Java
- GregorianCalendar equals() Method in Java
- GregorianCalendar isLeapYear() Method in Java
- GregorianCalendar setTimeZone() Method in Java
- GregorianCalendar getMinimum() Method in Java
- GregorianCalendar getLeastMaximum() Method in Java
- GregorianCalendar getMaximum() Method in Java
- GregorianCalendar getGregorianChange() Method
- Java.util.GregorianCalendar Class in Java
- Java.util.Collections.disjoint() Method in java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


