当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getActualMinimum(int)



相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Calendar getActualMinimum() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。