javafx: how to check if a date is greater than today's date?


If I have:

DatePicker dp = new DataPicker();

and at some point I want to know if the data is greater than today, how can I do it?

Example: if I want to book a room in a hotel from 21/04/2014 well, it should be impossible because today is 28/07/2014.

How can I do it in JavaFX ?

7/28/2014 1:28:20 PM

To ensure that a given Date chosenDate is after today, you can check

if (chosenDate.after(new Date())) {
    // valid (Date > today)
} else {
    // invalid (Date <= today)

Note that chosenDate should be a Date with hour, minute and second set to 0 since else it could accept a Date with the same day as today but a later hour than now.

7/28/2014 2:34:48 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow