如何使用GWT获取一个月内的天数列表?

如何使用GWT获取一个月内的天数列表?,gwt,gwt-2.4,Gwt,Gwt 2.4,GWT中此代码的计数器部分是什么 public int returnAllDaysOf(2012,6){ Calendar calendar = Calendar.getInstance(); calendar.set(2012, Calendar.FEBRUARY, 1); int daysOfFeb = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return da

GWT中此代码的计数器部分是什么

public int returnAllDaysOf(2012,6){

        Calendar calendar = Calendar.getInstance();

        calendar.set(2012, Calendar.FEBRUARY, 1);

        int daysOfFeb = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

        return daysOfFeb;

 }
提前感谢你的帮助

我想在客户端得到一个月的天数。我搜索了谷歌和StackOverFlow,但什么也没找到


例如2月有29天,比赛有31天等等

我不知道直接的方法,但你可以通过在日期上加上一个月,然后以天为单位计算差值来计算这个值:

最终日期myDate=。。。;
最终日期copyOfDate=CalendarUtil.copyDate(myDate);
CalendarUtil.AddMonthToDate(copyOfDate,1);
final int daysBetween=CalendarUtil.getDaysBetween(myDate,copyOfDate);
注意:如果myDate类似于2012-01-31,此选项也适用。copyOfDate是2012-03-02(因为二月没有31天),结果也是正确的。

作弊的方法:

int daysInCurrentMonth = new Date(year-1900, month+1, 0).getDate();

基本上将
Date
对象设置为下个月的
0th
天,然后得到当月的日期

注:
日期(整数年、整数月、整数日)
预计
年=日历年-1900
(即2014=114),月份基于
0
(即一月为0月)

是的,我知道这个构造函数不推荐使用,但我仍然使用它

        DateField dfMois = new DateField();

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(dfMois.getValue());

        Date date = dfMois.getValue();

        Date dateCopy = dateFin;

        dateCopy.setDate(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

        if(date.getMonth() == Calendar.FEBRUARY + 1){
            date.setDate(31 - dateCopy.getDate());
            date.setMonth(date.getMonth()-1);
        }
        else{
            date.setDate(dateCopy.getDate());
        }
        dfMois.setValue(date);

在你的代码中。。。它可以工作。

似乎是一个聪明的解决方案,我用另一种更简单的方法解决了我的问题,创建了一个月和相应天数的地图:)无论如何感谢回复:)这不是GWT兼容的代码,GWT中没有模拟日历。
        DateField dfMois = new DateField();

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(dfMois.getValue());

        Date date = dfMois.getValue();

        Date dateCopy = dateFin;

        dateCopy.setDate(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

        if(date.getMonth() == Calendar.FEBRUARY + 1){
            date.setDate(31 - dateCopy.getDate());
            date.setMonth(date.getMonth()-1);
        }
        else{
            date.setDate(dateCopy.getDate());
        }
        dfMois.setValue(date);