Open In App

GregorianCalendar getLeastMaximum() Method in Java

Last Updated : 05 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The java.util.GregorianCalendar.getLeastMaximum() method is an in-built function in Java which returns the lowest maximum value for a calendar field, passed as parameter to the function, of this GregorianCalendar instance. The lowest maximum value for any possible time value is defined as the largest 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 getMaximum(int calendarfield)

Parameters: This function accepts one mandatory parameter calendarfield of integer type referring to the calendar field whose lowest maximum value will be returned by the function.
Return Value: This method returns an integer value which is equal to the lowest maximum value for the specified calendar field.
Examples: 
 

Input : DAY_OF_MONTH
Output : 28

Input : WEEK_OF_MONTH
Output : 3

Below programs illustrate the working of java.util.GregorianCalendar.getMaximum() function:
Program 1:
 

Java




// Java program to illustrate getLeastMaximum()
 
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 lowest maximum for WEEK_OF_MONTH
      int maxm = cal.getLeastMaximum(
                   GregorianCalendar.WEEK_OF_MONTH);
      System.out.println("Lowest Maximum for"+
                   " WEEK_OF_MONTH field :" + maxm);
 
      // Get lowest maximum for DAY_OF_MONTH
      maxm = cal.getLeastMaximum(
                    GregorianCalendar.DAY_OF_MONTH);
      System.out.println("Lowest Maximum for"+
                     " DAY_OF_MONTH field:" + maxm);
   }
}


Output: 

Current Date and Time : Wed Aug 01 06:48:43 UTC 2018
Lowest Maximum for WEEK_OF_MONTH field :3
Lowest Maximum for DAY_OF_MONTH field:28

 

Program 2:
 

Java




// Java program to illustrate getLeastMaximum()
 
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 lowest maximum for YEAR
      int maxm = cal.getLeastMaximum(
                           GregorianCalendar.YEAR);
      System.out.println("Lowest Maximum for"+
                           " YEAR field :" + maxm);
 
      // Get lowest maximum for HOUR_OF_DAY
      maxm = cal.getLeastMaximum(
                    GregorianCalendar.HOUR_OF_DAY);
      System.out.println("Lowest Maximum for"+
                     " HOUR_OF_DAY field:" + maxm);
   }
}


Output: 

Current Date and Time : Wed Aug 01 06:48:45 UTC 2018
Lowest Maximum for YEAR field :292269054
Lowest Maximum for HOUR_OF_DAY field:23

 

Reference:https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#getLeastMaximum()
 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads