Home » Java programming language

Java GregorianCalendar getGreatestMinimum() Method with Example

GregorianCalendar Class getGreatestMinimum() method: Here, we are going to learn about the getGreatestMinimum() method of GregorianCalendar Class with its syntax and example.
Submitted by Preeti Jain, on February 15, 2020

GregorianCalendar Class getGreatestMinimum() method

  • getGreatestMinimum() method is available in java.util package.
  • getGreatestMinimum() method is used to get the greatest minimum value of the specified calendar field (fi) in this GregorianCalendar object.
  • getGreatestMinimum() method is a non-static method, it is accessible with class object only and if we try to access the method with class name then we will get an error.
  • getGreatestMinimum() method does not throw an exception at the time of returning greatest minimum value that the given field can hold.

Syntax:

    public int getGreatestMinimum(int fi);

Parameter(s):

  • int fi – represents the GregorianCalendar field (fi).

Return value:

The return type of this method is int, it returns greatest minimum value of the given field (fi).

Example:

// Java program to demonstrate the example 
// of int getGreatestMinimum(int fi) method of 
// GregorianCalendar

import java.util.*;

public class GetGreatestMinimumofGregorianCalendar {
    public static void main(String args[]) {
        // Instantiating a GregorianCalendar object
        GregorianCalendar ca = (GregorianCalendar) GregorianCalendar.getInstance();

        // Display current GregorianCalendar
        System.out.println("ca: " + ca.getTime());

        // By using getGreatestMinimum(int fi) method is
        // to return the greatest minimum month value
        int month = ca.getGreatestMinimum(GregorianCalendar.MONTH);

        // Display minimum value of the month
        System.out.println("ca.getGreatestMinimum(GregorianCalendar.MONTH): " + month);
    }
}

Output

ca: Sat Feb 15 09:04:46 GMT 2020
ca.getGreatestMinimum(GregorianCalendar.MONTH): 0


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.