Calendar類中的getGreatestMinimum(int calndr_field)方法用於返回此Calendar實例的給定日曆字段(int calndr_field)的最大值。
用法:
public abstract int getGreatestMinimum(int calndr_field)
參數:該方法采用一個參數calndr_field,該參數表示要操作的日曆字段。
返回值:該方法返回此日曆字段的最低最大值。
以下示例程序旨在說明Calendar類的getGreatestMinimum()方法的用法:
示例1:
// Java code to illustrate
// getGreatestMinimum() method
import java.util.*;
public class Java_Calendar_Demo {
public static void main(String[] args)
{
// Creating a calendar
Calendar calndr = new GregorianCalendar(2018, 6, 10);
// Calculating the highest min value
int rslt = calndr.getGreatestMinimum(Calendar.YEAR);
// Displaying the highest min value
System.out.println("The minimum year is: " + rslt);
}
}
輸出:
The minimum year is: 1
示例2:
// Java code to illustrate
// getGreatestMinimum() method
import java.util.*;
public class Java_Calendar_Demo {
public static void main(String[] args)
{
// Creating a calendar
Calendar calndr = Calendar.getInstance();
// Calculating the highest min value
int rslt = calndr.getGreatestMinimum(Calendar.MONTH);
// Displaying the highest min value
System.out.println("The minimum month is: " + rslt);
}
}
輸出:
The minimum month is: 0
參考: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getGreatestMinimum(int)
相關用法
- Java GregorianCalendar getGreatestMinimum()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getFirstDayOfWeek()用法及代碼示例
- Java Calendar toString()用法及代碼示例
- Java Calendar isLenient()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar getLeastMaximum()用法及代碼示例
- Java Calendar getMaximum()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar computeFields()用法及代碼示例
- Java Calendar computeTime()用法及代碼示例
- Java Calendar compareTo()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar getGreatestMinimum() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。