如何从DatePicker小部件计算两个日期之间的差异 [英] How to calculate difference between two date from DatePicker widget

查看:45
本文介绍了如何从DatePicker小部件计算两个日期之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GWT项目有一个问题:我只想计算两个DatePicker窗口小部件中两个日期(以天为单位)之间的差异.

I've a problem with my GWT project: i'm only interested to calculate the difference between two date (in days) from two DatePicker Widget.

这是我的代码,我主要从这里获取: http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/datepicker/client/DatePicker.html

This is my code, i take it mainly from here: http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/datepicker/client/DatePicker.html

    // Create a date picker "FROM: "
    final DatePicker datePicker1 = new DatePicker();
    datePicker1.addValueChangeHandler(new ValueChangeHandler<Date>() {
      public void onValueChange(ValueChangeEvent<Date> event) {
      Date date1 = datePicker1.getValue();
      }
    });
    // Set the default value
    datePicker1.setValue(new Date(), true);

    // Create a date picker "TO: "
    final DatePicker datePicker2 = new DatePicker();
    datePicker2.addValueChangeHandler(new ValueChangeHandler<Date>() {
       public void onValueChange(ValueChangeEvent<Date> event) {
       Date date2 = datePicker2.getValue();        
      }
    });
    // Set the default value
    datePicker2.setValue(new Date(), true);

    // =================DEBUG===================
    Button send = new Button("send", new ClickHandler(){
        public void onClick(ClickEvent event) {
            //calculate difference between date1 and date2
            days = (int) CalendarUtil.getDaysBetween(date1, date2);
            Window.alert("Differece: " + days);
        }
    });

但是当我在Eclipse中没有错误时,当我运行Web应用程序时却出现了以下错误:

but while i have no error in eclipse, when i run the web application i have this error:

[ERROR] [progetto] Uncaught exception escaped
com.google.gwt.event.shared.UmbrellaException: Exception caught: null
[...]

如有必要,我可以写出更多错误详细信息,但是它很长...

I can write more error details if necessary but it's very long...

您能告诉我如何解决此错误或如何使用替代方法进行计算吗?

Can you tell me how to fix this error or how to calculate it with an alternative methods?

谢谢.

推荐答案

在我看来,您的对象之一为null.在这种例外情况下调查例外情况,将会有更多详细信息.第二个告诉我,您在哪里计算代码的天数以及如何计算?如果您共享更多代码,将很有帮助.但我认为您在将date1和date2查找为空.如果可以的话,请分享更多代码,我将为您提供更多帮助,并在调试时牢记这一点.

it seems to me one of your object is null. look into exception under this exception, there would be more detail. Second tell me where are you calculating days in code and how? if you share more code it would be helpful. But I think you look for date1 and date2 for null. If you can please share more code, i will be more helpful and do the debugging keeping this in mind.

这篇关于如何从DatePicker小部件计算两个日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆