Java 日历 getActualMinimum()方法及示例
Calendar类的 getActualMinimum(int field_value) 方法用于返回指定的日历字段可能具有的最小值,该值基于该日历的时间值。
语法
public int getActualMinimum(int field_value)
参数: 该方法需要一个整数类型的参数 field_value ,指的是需要返回其最小值的日历。
返回值: 该方法返回所传递字段的最小值。
下面的程序说明了日历类的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://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getActualMinimum(int)