Java Calendar getGreatestMinimum() Method with Example



Description

The Java Calendar getGreatestMinimum(int field) method returns the highest minimum value for the given calendar field of this Calendar instance.

Declaration

Following is the declaration for java.util.Calendar.getGreatestMinimum() method

public abstract int getGreatestMinimum(int field)

Parameters

field − the given calendar field.

Return Value

Returns lowest maximum value of the given calendar field.

Exception

NA

Getting Greated Minimum Year from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getGreatestMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting greatest minimum value of Year and printing it.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar    
      Calendar cal = new GregorianCalendar();

      // print the greatest min. for year field
      int result = cal.getGreatestMinimum(Calendar.YEAR);
      System.out.println("The minimum is: " + result);
   }
}

Output

Let us compile and run the above program, this will produce the following result −

The minimum is: 1

Getting Greated Minimum Month from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getGreatestMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting greatest minimum value of Month using getGreatestMinimum() method and printing it.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar    
      Calendar cal = new GregorianCalendar();

      // print the greatest min. for month field
      int result = cal.getGreatestMinimum(Calendar.MONTH);
      System.out.println("The minimum is: " + result);
   }
}

Output

Let us compile and run the above program, this will produce the following result −

The minimum is: 0

Getting Greated Minimum Day from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getGreatestMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting greatest minimum value of Day using getGreatestMinimum() method and printing it.

package com.tutorialspoint;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar    
      Calendar cal = new GregorianCalendar();

      // print the greatest min. for day field
      int result = cal.getGreatestMinimum(Calendar.DATE);
      System.out.println("The minimum is: " + result);
   }
}

Output

Let us compile and run the above program, this will produce the following result −

The minimum is: 1
java_util_calendar.htm
Advertisements