P
Petra Neumann
Hi,
I have a problem comparing two Date objects:
I create the dates by parsing from a String like: 2/23/05 2:00 PM
by calling this function:
public static Date getDate(String date){
try{
df = new SimpleDateFormat("M/d/y h:m a");
Date myDate = df.parse(date);
return myDate;
}catch(Exception e){
System.out.println("ERROR "+e.getLocalizedMessage());
return null;
}
}
Each of these dates represents an update. Now in my code I want to check
if an update has been written to the file twice in which case I would
only have to use one. I do this by calling:
//I save the previous update as "lastUpdateDate".
//then I get the new update from a string read from a file as above
updateDate = getDate(dateString);
//now check for errors in the dataset
if(lastUpdateDate.before(updateDate)){
....
}
This should catch all errors where the new updateDate was before the
lastUpdateDate, or is equal to it.
However, sometimes it seems that the if clause is also true if
updateDate seems to represent the same date as lastUpdateDate, for
example as parsed from:
2/23/05 4:00 PM -> Wed Feb 23 16:00:00 MST 2005
2/23/05 4:00 PM -> Wed Feb 23 16:00:00 MST 2005
Any suggestions why this happens?
Cheers,
Petra
I have a problem comparing two Date objects:
I create the dates by parsing from a String like: 2/23/05 2:00 PM
by calling this function:
public static Date getDate(String date){
try{
df = new SimpleDateFormat("M/d/y h:m a");
Date myDate = df.parse(date);
return myDate;
}catch(Exception e){
System.out.println("ERROR "+e.getLocalizedMessage());
return null;
}
}
Each of these dates represents an update. Now in my code I want to check
if an update has been written to the file twice in which case I would
only have to use one. I do this by calling:
//I save the previous update as "lastUpdateDate".
//then I get the new update from a string read from a file as above
updateDate = getDate(dateString);
//now check for errors in the dataset
if(lastUpdateDate.before(updateDate)){
....
}
This should catch all errors where the new updateDate was before the
lastUpdateDate, or is equal to it.
However, sometimes it seems that the if clause is also true if
updateDate seems to represent the same date as lastUpdateDate, for
example as parsed from:
2/23/05 4:00 PM -> Wed Feb 23 16:00:00 MST 2005
2/23/05 4:00 PM -> Wed Feb 23 16:00:00 MST 2005
Any suggestions why this happens?
Cheers,
Petra