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:
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args) {
GregorianCalendar cal = (GregorianCalendar)
GregorianCalendar.getInstance();
System.out.println( "Current Date and Time : "
+ cal.getTime());
int minm = cal.getMinimum(GregorianCalendar.WEEK_OF_MONTH);
System.out.println( "Minimum for WEEK_OF_MONTH field :"
+ minm);
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:
import java.io.*;
import java.util.*;
class GFG {
public static void main(String[] args) {
GregorianCalendar cal = (GregorianCalendar)
GregorianCalendar.getInstance();
System.out.println( "Current Date and Time : "
+ cal.getTime());
int minm = cal.getMinimum(GregorianCalendar.YEAR);
System.out.println( "Minimum for YEAR field :"
+ minm);
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()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
27 Jul, 2018
Like Article
Save Article