1

我正在尝试用Calendarjava编写一个输出html带有表格内部的网页Calendar,但是在尝试获取特定年份中特定月份的天数时遇到了问题。

这是我正在使用的代码:

    //accept input from command prompt in form of MONTH, DAY, YEAR
    String date = args[0];
    SimpleDateFormat df = new SimpleDateFormat("MMMM dd, yyyy");
    Date convertedDate = new Date();
    try
    {
        convertedDate = df.parse(date);
    }
    catch(Exception e)
    {
        System.out.print(e);
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(convertedDate);
    year = cal.get(Calendar.YEAR);
    month = cal.get(Calendar.MONTH);
    day = cal.get(Calendar.DAY_OF_MONTH);



    //get number of days in month
    int numDays, startMonth;
    numDays = cal.getActualMaximum(DAY_OF_MONTH);

我从最后一行收到错误消息:

error: cannot find symbol and it points to the DAY_OF_MONTH variable.

我该如何解决这个问题?

4

1 回答 1

6

使用Calendar.DAY_OF_MONTH

numDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

它是类上的静态字段Calendar

于 2012-09-08T00:49:39.370 回答