📜  Java中的 Calendar getGreatestMinimum() 方法及示例

📅  最后修改于: 2022-05-13 01:55:49.807000             🧑  作者: Mango

Java中的 Calendar getGreatestMinimum() 方法及示例

Calendar 类中的getGreatestMinimum(int calndr_field )方法用于返回此 Calendar 实例的给定日历字段 (int calndr_field) 的最大最小值。

句法:

public abstract int getGreatestMinimum(int calndr_field)

参数:该方法采用一个参数calndr_field ,该参数引用要操作的日历字段。

返回值:该方法返回此日历字段的最低最大值。

下面的程序说明了 Calendar 类的 getGreatestMinimum() 方法的工作原理:
示例 1:

// Java code to illustrate
// getGreatestMinimum() method
  
import java.util.*;
public class Java_Calendar_Demo {
    public static void main(String[] args)
    {
        // Creating a calendar
        Calendar calndr = new GregorianCalendar(2018, 6, 10);
  
        // Calculating the highest min value
        int rslt = calndr.getGreatestMinimum(Calendar.YEAR);
  
        // Displaying the highest min value
        System.out.println("The minimum year is: " + rslt);
    }
}
输出:
The minimum year is: 1

示例 2:

// Java code to illustrate
// getGreatestMinimum() method
  
import java.util.*;
public class Java_Calendar_Demo {
    public static void main(String[] args)
    {
        // Creating a calendar
        Calendar calndr = Calendar.getInstance();
  
        // Calculating the highest min value
        int rslt = calndr.getGreatestMinimum(Calendar.MONTH);
  
        // Displaying the highest min value
        System.out.println("The minimum month is: " + rslt);
    }
}
输出:
The minimum month is: 0

参考: https: Java/util/Calendar.html#getGreatestMinimum(int)