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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。