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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。