📌  相关文章
📜  Java中的 GregorianCalendar getMinimum() 方法

📅  最后修改于: 2022-05-13 01:54:26.248000             🧑  作者: Mango

Java中的 GregorianCalendar getMinimum() 方法

Java .util.GregorianCalendar.getMinimum()方法是Java中的一个内置函数,它返回作为参数传递给函数的特定日历字段的最小值。对于任何可能的时间值,它是 get() 方法返回的最小值,同时考虑到 getFirstDayOfWeek()、getMinimalDaysInFirstWeek()、getGregorianChange() 和 getTimeZone() 方法的当前值。

句法:

public int getMinimum(int calendarfield)

参数:该函数接受一个整数类型的强制参数calendarfieldGregorianCalender 实例的最小值将由该函数返回。

返回值:
此方法返回GregorianCalender 实例的指定日历字段的最小值。

例子:

Input : DAY_OF_MONTH
Output : 1

Input : WEEK_OF_MONTH
Output : 0

下面的程序说明了Java.util.GregorianCalendar.getMinimum()函数的使用:

方案一:

// 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

方案二:

// 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: Java/util/GregorianCalendar.html#getMinimum()