I need to compare a Calendar time to Date. I wrote below code.
Calendar now = Calendar.getInstance();
now.set(Calendar.SECOND, 0);
Date date = new Date();
date.setSeconds(0);
System.out.println(date);
System.out.println(now.getTime());
System.out.println(date.compareTo(now.getTime()));
Output is
Fri Dec 01 16:54:00 IST 2017
Fri Dec 01 16:54:00 IST 2017
1
It seems util date is bigger than calendar date. Why is it failing? what is the write way of comparing these dates?
Edit 1:- My problem is I need to compare a util date (stored in database) lets say 2017-12-01 16:41:00.0 to current Date and time, what is write approach?