Я использую GXT/ExtGWT. У меня ниже кода, который сравнивает две даты.ClassCastException при сравнении дат?
private DateField startDateField = new DateField();
private DateField endDateField = new DateField();
Date date = new Date();
CalendarUtil.addDaysToDate(date, -1);
startDateField.setValue(date);
endDateField.setValue(new Date());
Date fromDate = startDateField.getValue();
Date toDate = endDateField.getValue();
Date differenceBetweenDates = new Date(fromDate.getTime());
CalendarUtil.addMonthsToDate(differenceBetweenDates, 6);
if (differenceBetweenDates.before(toDate)) {
MessageBox.alert("Alert","Date range should not exceed six months", null);
return false;
} else{
return true;
}
Здесь в datefields FromDate я выбрал в качестве 0012-12-30
и Todate как 0012-12-31
.
Когда выполняется строка differenceBetweenDates.before(toDate)
, я становлюсь ниже исключения. Пожалуйста, помогите мне. Я здесь что-то не так?
java.lang.ClassCastException: sun.util.calendar.JulianCalendar$Date cannot be cast to sun.util.calendar.Gregorian$Date
Какой номер вы получаете исключение на линии? – Sap
Привет Спасибо за ваш ответ. Ниже приведена строка, в которой я получаю исключение .if (differenceBetweenDates.before (toDate)). – user1016403