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

前端 未结 3 619
深忆病人
深忆病人 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:35

    Create a new Date object this way:

    Date now = new Date(System.currentTimeMillis());
    

    and use int result = now.compareTo(theOtherDate);

    result will be an int < 0 if now Date is less than the theOtherDate Date, 0 if they are equal, and an int > 0 if this Date is greater.

提交回复
热议问题