为什么我用getMaximum(Calendar.WEEK_OF_MONTH)得到的都是6
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR,  year);
c.set(Calendar.MONTH, month);
System.out.println(c.getMaximum(Calendar.WEEK_OF_MONTH));
改成
System.out.println(c.getActualMaximum(Calendar.WEEK_OF_MONTH));就对了
getMaximum和getActualMaximum有什么区别

解决方案 »

  1.   

    public abstract int getMaximum(int field)
        Returns the maximum value for the given calendar field of this Calendar instance. The maximum value is defined as the largest value returned by the get method for any possible time value. The maximum value depends on calendar system specific parameters of the instance. public int getActualMaximum(int field)
         Returns the maximum value that the specified calendar field could have, given the time value of this Calendar. For example, the actual maximum value of the MONTH field is 12 in some years, and 13 in other years in the Hebrew calendar system. 
    The default implementation of this method uses an iterative algorithm to determine the actual maximum value for the calendar field. Subclasses should, if possible, override this with a more efficient implementation.