Open In App

GregorianCalendar getMinimum() Method in Java

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The java.util.GregorianCalendar.getMinimum() method is an in-built function in Java which returns the minimum value for the particular calendar field passed as parameter to the function. For any possible time value, it is the smallest value that the get() method returns, considering the current values of the getFirstDayOfWeek(), getMinimalDaysInFirstWeek(), getGregorianChange() and getTimeZone() methods as well.

Syntax:

public int getMinimum(int calendarfield)

Parameters: This function accepts one mandatory parameter calendarfield of integer type whose minimum value for this GregorianCalender instance will be returned by the function.

Return Value:
This method returns the minimum value for the specified calendar field for this GregorianCalender instance.

Examples:

Input : DAY_OF_MONTH
Output : 1

Input : WEEK_OF_MONTH
Output : 0

Below programs illustrate the use of java.util.GregorianCalendar.getMinimum() function:

Program 1:




// Java Program to illustrate getMinimum() function 
// GregorianCalender
  
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());
  
      // Display minimum for WEEK_OF_MONTH
      int minm = cal.getMinimum(GregorianCalendar.WEEK_OF_MONTH);
      System.out.println("Minimum for WEEK_OF_MONTH field :"
                                                   + minm);
  
      // Display minimum for DAY_OF_MONTH
      minm = cal.getMinimum(GregorianCalendar.DAY_OF_MONTH);
      System.out.println("Minimum for DAY_OF_MONTH field:"
                                                  + minm);
   }
}


Output:

Current Date and Time : Fri Jul 27 11:40:24 UTC 2018
Minimum for WEEK_OF_MONTH field :0
Minimum for DAY_OF_MONTH field:1

Program 2:




// Java Program to illustrate getMinimum() function 
// GregorianCalender
  
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());
  
      // Display minimum for YEAR
      int minm = cal.getMinimum(GregorianCalendar.YEAR);
      System.out.println("Minimum for YEAR field :"
                                          + minm);
  
      // Display minimum for HOUR_OF_DAY
      minm = cal.getMinimum(GregorianCalendar.HOUR_OF_DAY);
      System.out.println("Minimum for HOUR_OF_DAY field :"
                                                  + minm);
   }
}


Output:

Current Date and Time : Fri Jul 27 11:40:28 UTC 2018
Minimum for YEAR field :1
Minimum for HOUR_OF_DAY field :0

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



Last Updated : 27 Jul, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads