Validate Item Fall Within Start Date And End Date

前端 未结 4 1564
不思量自难忘°
不思量自难忘° 2021-01-26 18:16

I have a java program which will check for start date and end date of each item. Each Item must have their own specific start date and end date range. And this system will promp

4条回答
  •  后悔当初
    2021-01-26 18:45

    You can do something like this:

    public class DateDemo {
    
        public static void main(String[] args) {
    
            Date date = new Date(11, 5, 21);
            Date date2 = new Date(15, 1, 21);
    
            // tests if date2 is before date and prints result
            boolean before = date2.before(date);
            if (before) {
                System.out.println("Date 2 is before date: " + before);
                throw new RuntimeException("Error with dates");
            }
    
        }
    }
    

    Of course, it is just an example, since I don't know where this date is coming from. And you will have to do it inside a loop to verify all of them.

提交回复
热议问题