當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。