how do i compare current date with user input date from date picker

前端 未结 3 605
深忆病人
深忆病人 2021-01-07 02:08

I am trying to keep constraint on date and time. I want that if user tries to set date less than current date then it should show alert, and same thing is to be done with ti

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 02:41

    protected boolean checkDateValidity(Date date){
            Calendar cal = new GregorianCalendar(date.getYear() + 1900, date.getMonth(), date.getDate(), date.getHours(), date.getMinutes());
            if((cal.getTimeInMillis()-System.currentTimeMillis()) <= 0){
                return false;
            }else{
                return true;
            }
        }
    

    pass the date object to this method

    if it returns false means you will show alert message

提交回复
热议问题