Java Calendar getMinimum() Method



Description

The Java Calendar getMinimum() method returns the minimum value for the given calendar field.

Declaration

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

public abstract int getMinimum(int field)

Parameters

field − the calendar field.

Return Value

The method returns the minimum value for the field entered.

Exception

NA

Getting Minimum Year from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting minimum value of Year using getMinimum() 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 minimum for year field
      int result = cal.getMinimum(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 Minimum Month from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting minimum value of Month using getMinimum() 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 minimum for month field
      int result = cal.getMinimum(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 Minimum Day from a Current Dated GregorianCalendar Instance Example

The following example shows the usage of Java Calendar getMinimum() method. We're creating an instance of a GregorianCalendar of current date. Then we're getting minimum value of Day using getMinimum() 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 minimum for day field
      int result = cal.getMinimum(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