Android:检查系统日期是否小于或等于指定日期

Ros*_*e18 1 java android compare date

在我的 android 应用程序中有一个用户定义的日期。此日期应大于或等于系统日期。如果是,则过程将继续。如果不是,那么它会提示后续日期应该大于或等于系统日期

我使用了这个代码段。

if (sys_date.after(df.parse((date.getText().toString())))) {
    Toast.makeText(getActivity(), "Follow up date should be greater than or equal to system date", Toast.LENGTH_SHORT).show();
} else {
    //process will continue
}
Run Code Online (Sandbox Code Playgroud)

但问题是:即使用户定义的日期等于系统日期,它也会给出吐司消息。

任何人都可以如此友好地解释这里发生了什么以及我如何解决这个问题。

提前谢谢

Roh*_*5k2 6

我正在使用这个

public static boolean isAfterToday(int year, int month, int day)
{
    Calendar today = Calendar.getInstance();
    Calendar myDate = Calendar.getInstance();

    myDate.set(year, month, day);

    if (myDate.before(today)) 
    {
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)