Calendar类的getActualMaximum(int field_value)方法用于根据此Calendar的时间值返回指定日历字段可能具有的最大值。
用法:
public int getActualMaximum(int field_value)
参数:该方法采用一个整数类型的参数field_value,表示需要返回最大值的日历。
返回值:该方法返回传递的字段的最大值。
以下示例程序旨在说明Calendar类的getActualMaximum()方法的用法:
示例1:
// Java Code to illustrate
// getActualMaximum() Method
import java.util.*;
public class CalendarClassDemo {
public static void main(String args[])
{
// Creating a calendar
Calendar calndr
= Calendar.getInstance();
// Getting the maximum value that
// year field can have
int yr
= calndr.getActualMaximum(Calendar.YEAR);
System.out.println("The Maximum year: "
+ yr);
// Getting the maximum value that
// month field can have
int mon
= calndr.getActualMaximum(Calendar.MONTH);
System.out.println("The Maximum Month is: "
+ mon);
}
}
输出:
The Maximum year: 292278994 The Maximum Month is: 11
示例2:
// Java Code to illustrate
// getActualMaximum() Method
import java.util.*;
public class CalendarClassDemo {
public static void main(String args[])
{
// Creating a calendar object
Calendar calndr
= new GregorianCalendar(2018, 9, 2);
// Getting the maximum value that
// year field can have
int yr
= calndr.getActualMaximum(Calendar.YEAR);
System.out.println("The Maximum year: "
+ yr);
// Getting the maximum value that
// month field can have
int mon
= calndr.getActualMaximum(Calendar.MONTH);
System.out.println("The Maximum Month is: "
+ mon);
}
}
输出:
The Maximum year: 292278993 The Maximum Month is: 11
参考: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getActualMaximum(int)
相关用法
- Java Calendar set()用法及代码示例
- Java Calendar add()用法及代码示例
- Java Calendar get()用法及代码示例
- Java Calendar getMaximum()用法及代码示例
- Java Calendar getAvailableLocales()用法及代码示例
- Java Calendar getDisplayName()用法及代码示例
- Java Calendar getDisplayNames()用法及代码示例
- Java Calendar getLeastMaximum()用法及代码示例
- Java Calendar getFirstDayOfWeek()用法及代码示例
- Java Calendar getInstance()用法及代码示例
- Java Calendar getActualMinimum()用法及代码示例
- Java Calendar clear()用法及代码示例
- Java Calendar toString()用法及代码示例
- Java Calendar compareTo()用法及代码示例
- Java Calendar complete()用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Calendar getActualMaximum() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。