java.util.Calendar getActualMaximum()方法

java.util.Calendar.getActualMaximum() 方法返回一个整数值,该整数值是作为参数传递给getActualMaximum() 方法的日历字段的最大可能值。例如,DATE字段的最大值为31,而MONTH字段的最大值为11。

1 语法

public int getActualMaximum(int field)  

2 参数

field:像月,时,DAY_OF_MONTH等日历Field

3 返回值

返回一个整数值,该整数值是作为参数传递的字段的最大值。

4 示例1 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar getActualMaximum()方法的例子
 */
import java.util.*;  
public class CalendargetactualmaximumExample1 {  
   public static void main(String[] args) {  
      // create a calendar  
      Calendar cal1 = Calendar.getInstance();  
     GregorianCalendar cal2 = (GregorianCalendar) GregorianCalendar.getInstance();  
      // get the maximum value that year field can have  
      int year = cal1.getActualMaximum(Calendar.YEAR);  
      int year2 = cal2.getActualMaximum(GregorianCalendar.YEAR);  
      System.out.println("Maximum year value of Calendar is:" + year);  
System.out.println("Maximum year value of Gregorian Calendar is :" + year2);     
   }  
}

输出结果为:

Maximum year value of Calendar is:292278994
Maximum year value of Gregorian Calendar is :292278994

5 示例2

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar getActualMaximum()方法的例子
 */
import java.util.*;  
public class CalendargetactualmaximumExample2 {  
   public static void main(String[] args) {  
      // create a calendar  
      Calendar cal = Calendar.getInstance();  
      // get the maximum value that year field can have  
      int  month = cal.getActualMaximum(Calendar.MONTH);  
      System.out.println("Maximum Month:" + month);  
      int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);  
      System.out.println("Maximum DAY:" + day);  
   }  
}  

输出结果为:

Maximum Month:11
Maximum DAY:31

6 示例3

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar getActualMaximum()方法的例子
 */
import java.util.*;  
public class CalendargetactualmaximumExample3 {  
   public static void main(String[] args) {  
      // create a calendar  
      Calendar cal = Calendar.getInstance();  
 // get the maximum value that year field can have  
      int hour = cal.getActualMaximum(Calendar.HOUR);  
      System.out.println("Maximum HOUR value:" + hour);  
      int mnt = cal.getActualMaximum(Calendar.MINUTE);  
      System.out.println("Maximum MINUTE value:" + mnt);  
      int scnd = cal.getActualMaximum(Calendar.SECOND);  
      System.out.println("Maximum SECOND value:" + scnd);  
   }  
} 

输出结果为:

Maximum HOUR value:11
Maximum MINUTE value:59
Maximum SECOND value:59

 

热门文章

优秀文章