检查所选日期是否在今天的一周内(Joda时间)

时间:2016-06-18 12:52:33

标签: android date time jodatime

应用程序应显示文本"下一个"在文本视图中,仅当所选日期是从今天开始的一周内,但它没有......

我尝试过这一行:

(todayDate.withTimeAtStartOfDay().plusWeeks(1).isEqual(eventToDisplay.getEventDate().withTimeAtStartOfDay()))

代码的其他部分正常运作,只有这不是

DateTime todayDate = new DateTime()。now();

        //If the event's date equal to today's date
        if ((Days.daysBetween(eventToDisplay.getEventDate().withTimeAtStartOfDay(),todayDate.withTimeAtStartOfDay()).getDays())==0)
        {
            contentView.setTextViewText(R.id.eventDayOfTheWeekTxt,"היום"+"("+eventToDisplay.getEventDate().dayOfWeek().getAsText()+")");

        }

        else {

            if (Days.daysBetween(todayDate.withTimeAtStartOfDay(),eventToDisplay.getEventDate().withTimeAtStartOfDay()).getDays()==1)
                contentView.setTextViewText(R.id.eventDayOfTheWeekTxt,"tomorrow"+"("+eventToDisplay.getEventDate().dayOfWeek().getAsText()+")");

            else {

                if ((Days.daysBetween(todayDate.withTimeAtStartOfDay(),eventToDisplay.getEventDate().withTimeAtStartOfDay()).getDays())<7)
                {
                    contentView.setTextViewText(R.id.eventDayOfTheWeekTxt, eventToDisplay.getEventDate().dayOfWeek().getAsText()+"The upcoming ");

                }

                else {
                    if (todayDate.withTimeAtStartOfDay().plusWeeks(1).isEqual(eventToDisplay.getEventDate().withTimeAtStartOfDay()))
                    {
                        contentView.setTextViewText(R.id.eventDayOfTheWeekTxt, eventToDisplay.getEventDate().dayOfWeek().getAsText()+"The next");

                    }

                    else
                    contentView.setTextViewText(R.id.eventDayOfTheWeekTxt, eventToDisplay.getEventDate().dayOfWeek().getAsText());
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

todayDate.withTimeAtStartOfDay().plusWeeks(1)
    .isEqual(eventToDisplay.getEventDate().withTimeAtStartOfDay())