0

I am trying to compare Date objects in Java but when I test it, it fails because (I think) of seconds and milliseconds.

Date date = (Date) jSpinner.getValue();
Date now = Calendar.getInstance().getTime();

if(date.before(now)) 
   System.out.println("Error: Date too early");
else
   System.out.println("Date is good");

So when I pick from the JSpinner today's date and time (up to minutes) the comparison with now should print the second statement but prints the first one. So how do you tell the date object to set seconds and milliseconds to 0?

kuranes
  • 546
  • 1
  • 6
  • 16

1 Answers1

0

You should be able to use Calendar API to zero out the seconds and milliseconds to zero.

https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#set(int,%20int)