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


Java GregorianCalendar getMinimum()用法及代碼示例


java.util.GregorianCalendar.getMinimum()方法是Java中的內置函數,它返回作為參數傳遞給該函數的特定日曆字段的最小值。對於任何可能的時間值,它也是get()方法返回的最小值,同時考慮getFirstDayOfWeek(),getMinimalDaysInFirstWeek(),getGregorianChange()和getTimeZone()方法的當前值。

用法:

public int getMinimum(int calendarfield)

參數:該函數接受一個整數類型的強製性參數calendarfield,該函數的該GregorianCalender實例的最小值將返回。

返回值:
此方法為此GregorianCalender實例返回指定日曆字段的最小值。


例子:

Input : DAY_OF_MONTH
Output : 1

Input : WEEK_OF_MONTH
Output : 0

以下程序說明了java.util.GregorianCalendar.getMinimum()函數的用法:

示例1:

// Java Program to illustrate getMinimum() function  
// GregorianCalender 
  
import java.io.*; 
import java.util.*; 
  
class GFG { 
     public static void main(String[] args) { 
      
      // Create a new calendar 
      GregorianCalendar cal = (GregorianCalendar)  
                        GregorianCalendar.getInstance(); 
  
      // Display the current date and time 
      System.out.println("Current Date and Time : "
                                    + cal.getTime()); 
  
      // Display minimum for WEEK_OF_MONTH 
      int minm = cal.getMinimum(GregorianCalendar.WEEK_OF_MONTH); 
      System.out.println("Minimum for WEEK_OF_MONTH field :"
                                                   + minm); 
  
      // Display minimum for DAY_OF_MONTH 
      minm = cal.getMinimum(GregorianCalendar.DAY_OF_MONTH); 
      System.out.println("Minimum for DAY_OF_MONTH field:"
                                                  + minm); 
   } 
}
輸出:
Current Date and Time : Fri Jul 27 11:40:24 UTC 2018
Minimum for WEEK_OF_MONTH field :0
Minimum for DAY_OF_MONTH field:1

示例2:

// Java Program to illustrate getMinimum() function  
// GregorianCalender 
  
import java.io.*; 
import java.util.*; 
  
class GFG { 
     public static void main(String[] args) { 
      
      // Create a new calendar 
      GregorianCalendar cal = (GregorianCalendar)  
                        GregorianCalendar.getInstance(); 
  
      // Display the current date and time 
      System.out.println("Current Date and Time : "
                                         + cal.getTime()); 
  
      // Display minimum for YEAR 
      int minm = cal.getMinimum(GregorianCalendar.YEAR); 
      System.out.println("Minimum for YEAR field :"
                                          + minm); 
  
      // Display minimum for HOUR_OF_DAY 
      minm = cal.getMinimum(GregorianCalendar.HOUR_OF_DAY); 
      System.out.println("Minimum for HOUR_OF_DAY field :"
                                                  + minm); 
   } 
}
輸出:
Current Date and Time : Fri Jul 27 11:40:28 UTC 2018
Minimum for YEAR field :1
Minimum for HOUR_OF_DAY field :0

參考:https://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#getMinimum()



相關用法


注:本文由純淨天空篩選整理自RICHIK BHATTACHARJEE大神的英文原創作品 GregorianCalendar getMinimum() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。