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


Java GregorianCalendar getLeastMaximum()用法及代码示例


java.util.GregorianCalendar.getLeastMaximum()方法是Java中的内置函数,该函数返回此GregorianCalendar实例的日历字段的最低最大值,作为参数传递给该函数。任何可能的时间值的最低最大值定义为get方法返回的最大值,其中考虑了getFirstDayOfWeek,getMinimalDaysInFirstWeek,getGregorianChange和getTimeZone方法的当前值。

用法:

public int getMaximum(int calendarfield)

参数:该函数接受一个整数类型的强制性参数calendarfield,该整数类型引用该函数将返回其最小值的日历字段。


返回值:此方法返回一个整数值,该值等于指定日历字段的最低最大值。

例子:

Input : DAY_OF_MONTH
Output : 28

Input : WEEK_OF_MONTH
Output : 3

以下程序说明了java.util.GregorianCalendar.getMaximum()函数的工作:

示例1:

// Java program to illustrate getLeastMaximum() 
  
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 lowest maximum for WEEK_OF_MONTH 
      int maxm = cal.getLeastMaximum( 
                   GregorianCalendar.WEEK_OF_MONTH); 
      System.out.println("Lowest Maximum for"+ 
                   " WEEK_OF_MONTH field :" + maxm); 
  
      // Get lowest maximum for DAY_OF_MONTH 
      maxm = cal.getLeastMaximum( 
                    GregorianCalendar.DAY_OF_MONTH); 
      System.out.println("Lowest Maximum for"+ 
                     " DAY_OF_MONTH field:" + maxm); 
   } 
}
输出:
Current Date and Time : Wed Aug 01 06:48:43 UTC 2018
Lowest Maximum for WEEK_OF_MONTH field :3
Lowest Maximum for DAY_OF_MONTH field:28

示例2:

// Java program to illustrate getLeastMaximum() 
  
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 lowest maximum for YEAR 
      int maxm = cal.getLeastMaximum( 
                           GregorianCalendar.YEAR); 
      System.out.println("Lowest Maximum for"+ 
                           " YEAR field :" + maxm); 
  
      // Get lowest maximum for HOUR_OF_DAY 
      maxm = cal.getLeastMaximum( 
                    GregorianCalendar.HOUR_OF_DAY); 
      System.out.println("Lowest Maximum for"+ 
                     " HOUR_OF_DAY field:" + maxm); 
   } 
}
输出:
Current Date and Time : Wed Aug 01 06:48:45 UTC 2018
Lowest Maximum for YEAR field :292269054
Lowest Maximum for HOUR_OF_DAY field:23

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



相关用法

注:本文由纯净天空筛选整理自RICHIK BHATTACHARJEE大神的英文原创作品 GregorianCalendar getLeastMaximum() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文的传播和使用请遵循“署名-相同方式共享 4.0 国际 (CC BY-SA 4.0)”协议。