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

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

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

Calendar 类的getActualMinimum(int field_value )方法用于根据此 Calendar 的时间值返回指定日历字段可能具有的最小值。

句法:

public int getActualMinimum(int field_value)

参数:该方法接受一个整数类型的参数field_value ,是指需要返回最小值的日历。

返回值:该方法返回传递的字段的最小值。

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

// Java Code to illustrate
// getActualMinimum() Method
  
import java.util.*;
  
public class CalendarClassDemo {
    public static void main(String args[])
    {
        // Creating a calendar
        Calendar calndr = Calendar.getInstance();
  
        // Getting the Minimum value that
        // year field can have
        int yr
            = calndr.getActualMinimum(Calendar.YEAR);
        System.out.println("The Minimum year: "
                           + yr);
  
        // Getting the Minimum value that
        // month field can have
        int mon
            = calndr.getActualMinimum(Calendar.MONTH);
        System.out.println("The Minimum Month is: "
                           + mon);
    }
}
输出:
The Minimum year: 1
The Minimum Month is: 0

示例 2:

// Java Code to illustrate
// getActualMinimum() Method
  
import java.util.*;
  
public class CalendarClassDemo {
    public static void main(String args[])
    {
        // Creating a calendar object
        Calendar calndr
            = new GregorianCalendar(2018, 9, 2);
  
        // Getting the Minimum value that
        // year field can have
        int yr
            = calndr.getActualMinimum(Calendar.YEAR);
        System.out.println("The Minimum year: "
                           + yr);
  
        // Getting the Minimum value that
        // month field can have
        int mon
            = calndr.getActualMinimum(Calendar.MONTH);
        System.out.println("The Minimum Month is: "
                           + mon);
    }
}
输出:
The Minimum year: 1
The Minimum Month is: 0

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