I'm trying to compare two dates of the same day.
The first in the format date1 = Fri Mar 24 00:00:00 CET 2017 the second is date2 = 2017-03-24 09:59:39.0
The date1 is retrieved from UI.
The date2 is rigistred in data base as a dateTime
The issue is when comparing the two dates, i always got the the value 1 when using the following method of Timestamp Class of java.sql package
date2.compareTo(date1);
public int compareTo(Timestamp ts) {
long thisTime = this.getTime();
long anotherTime = ts.getTime();
int i = (thisTime<anotherTime ? -1 :(thisTime==anotherTime?0 :1));
if (i == 0) {
if (nanos > ts.nanos) {
return 1;
} else if (nanos < ts.nanos) {
return -1;
}
}
return i;
}
I'm looking how to convert the date1 to a date of today with hours of midnight in order to have 0 as a return value.