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()
相关用法
- Java Calendar getLeastMaximum()用法及代码示例
- Java GregorianCalendar add()用法及代码示例
- Java GregorianCalendar equals()用法及代码示例
- Java GregorianCalendar isLeapYear()用法及代码示例
- Java GregorianCalendar getGreatestMinimum()用法及代码示例
- Java GregorianCalendar clone()用法及代码示例
- Java GregorianCalendar getMaximum()用法及代码示例
- Java GregorianCalendar getMinimum()用法及代码示例
- Java GregorianCalendar getTimeZone()用法及代码示例
- Java GregorianCalendar hashCode()用法及代码示例
- Java GregorianCalendar setTimeZone()用法及代码示例
- Java Java.util.GregorianCalendar用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
注:本文由纯净天空筛选整理自RICHIK BHATTACHARJEE大神的英文原创作品 GregorianCalendar getLeastMaximum() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。