Judging the date of all evil...
Use
D1.getTime () = d2.getTime ();
(Provided that the year, month, day, hour, and minute of the Date have been specified at the time of new Date (xxxxxxx)
I didn't expect the result of loop 100 times to be 2-5 times. The returned value is false.
After carefully following the data value of d1.getTime (), the last millisecond count is different each time. Does jdk return the current millisecond count when the millisecond value is not specified? No way. It's hard to track data in milliseconds...
Java code
Public static Boolean compareDate (Date d1, Date d2 ){
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
String s1 = sdf. format (d1 );
String s2 = sdf. format (d2 );
If (s1.equals (s2) return true;
Else return false;
}
We had to use the string method for comparison! It is estimated that this item will be assigned a value of 0 in milliseconds, so there should be no problem, but for precision, it only takes the year: Month: Day, the demand for a small loop range, so we have to compare the strings!
If you can see that there are still good solutions, please kindly advise!