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


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



java.util.GregorianCalendar.getGreatestMinimum()方法是Java中的內置函數,該函數返回此GregorianCalendar實例的日曆字段的最大值(作為參數傳遞給該函數)。任何可能的時間值的最高最小值定義為get方法返回的最小值,其中getFirstDayOfWeek,getMinimalDaysInFirstWeek,getGregorianChange和getTimeZone方法的當前值都已考慮在內。

用法:

public int getGreatestMinimum(int calendarfield)

參數:該函數接受一個強製性的整數類型的日曆字段,該最大值的最小值將由該函數返回。


返回值:此方法返回一個整數,該整數表示指定日曆字段的最高最小值。

例子:

Input : DAY_OF_MONTH
Output : 1

Input : WEEK_OF_MONTH
Output : 0

以下程序說明了java.util.GregorianCalendar.getGreatestMaximum()函數的工作:
示例1:

// Java Program to illustrate getGreatestMinimum() 
  
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()); 
  
      // Greatest minimum for WEEK_OF_MONTH 
      int minm = cal.getGreatestMinimum( 
                   GregorianCalendar.WEEK_OF_MONTH); 
      System.out.println("Greatest Minimum for"+ 
                   " WEEK_OF_MONTH field :" + minm); 
  
      // Get greatest minimum for DAY_OF_MONTH 
      minm = cal.getGreatestMinimum( 
                    GregorianCalendar.DAY_OF_MONTH); 
      System.out.println("Greatest Minimum for"
                    +" DAY_OF_MONTH field:" + minm); 
   } 
}
輸出:
Current Date and Time : Wed Aug 01 07:21:14 UTC 2018
Greatest Minimum for WEEK_OF_MONTH field :0
Greatest Minimum for DAY_OF_MONTH field:1

示例2:

// Java Program to illustrate getGreatestMinimum() 
  
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()); 
  
      // Get greatest minimum for YEAR 
      int minm = cal.getGreatestMinimum 
                         (GregorianCalendar.YEAR); 
      System.out.println("Greatest Minimum for"+ 
                           " YEAR field :" + minm); 
  
      // Get greatest minimum for HOUR_OF_DAY 
      minm = cal.getGreatestMinimum( 
                    GregorianCalendar.HOUR_OF_DAY); 
      System.out.println("Greatest Minimum for"+ 
                     " HOUR_OF_DAY field:" + minm); 
   } 
}
輸出:
Current Date and Time : Wed Aug 01 07:21:16 UTC 2018
Greatest Minimum for YEAR field :1
Greatest Minimum for HOUR_OF_DAY field:0

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



相關用法


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