-2

I'm creating equation to check if the current date greater than the end date or the current date less than the end date with more than 15 days and this's my code and doesn't work for the second part of equation . what would be the error??

if (cal.compareTo(gndr1) >= 0 || cal.compareTo(gndr1) > 15) {
    if (gndr2 == 0) {
        new check2().setVisible(true);
    } else {
        new themainwindow().setVisible(true);
    }
} else {
    new themainwindow().setVisible(true);
}
vinS
  • 1,417
  • 5
  • 24
  • 37
  • covert them in milliseconds and then compare the difference. – Abhishek Dec 08 '17 at 03:30
  • 2
    No, do NOT convert them to milliseconds and compare the difference. If you want a number of days, but you work in milliseconds, you get errors when daylight savings starts and stops. Please ignore any advice that talks about milliseconds. – Dawood ibn Kareem Dec 08 '17 at 03:35

1 Answers1

0

Unless you’ve implemented your own compareTo it’s only ever going to return -1, 0 or 1 based on whether the object is less than, equal or greater than the other. Hence you’ll never pass the >=15 condition.

Matt
  • 2,063
  • 1
  • 14
  • 35