-1

我试图从我的日历中禁用今天之前的日期,但日期没有被禁用。这是我的代码。

DateTime dateTime = this.datetimeList.get(position);

if (dateTime.isBefore(getToday())) {
                cellView.setBackgroundResource(resources
                        .getColor(com.caldroid.R.color.caldroid_sky_blue));

tv1.setEnabled(false);
            tv1.setTextColor(convertView.getResources().getColor(R.color.caldroid_white));
            }

这是比较日期的正确方法吗?

4

1 回答 1

0

尝试这个 :

if (removeTime(questionDate).equals(removeTime(today)) 
  ...

public Date removeTime(Date date) {    
    Calendar cal = Calendar.getInstance();  
    cal.setTime(date);  
    cal.set(Calendar.HOUR_OF_DAY, 0);  
    cal.set(Calendar.MINUTE, 0);  
    cal.set(Calendar.SECOND, 0);  
    cal.set(Calendar.MILLISECOND, 0);  
    return cal.getTime(); 
}
于 2013-05-30T09:23:31.907 回答