aspose file tools*
The moose likes Beginning Java and the fly likes date.after() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "date.after() problem" Watch "date.after() problem" New topic
Author

date.after() problem

Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I have two strings that I am converting to dates:

SimpleDateFormat sdf_date = new SimpleDateFormat("dd-MMM-yyyy hh:mm");
s_now = "24-Oct-2004 17:14"
s_task_complete_by_datetime = "24-Oct-2004 17:15"

dt_now = sdf_date.parse(s_now);
dt_complete_by = sdf_date.parse(s_task_complete_by_datetime);

if(dt_complete_by.after(dt_now)){
//do something
}
else
{
//do something else
}

when I run this code, I get the error: invalid date

Also, I wrote to a log dt_complete_by and dt_now:
dt_now = Sun Oct 24 17:14:00 CDT 2004
dt_complete_by = Sun Oct 24 17:15:00 CDT 2004

Any ideas?
Greg T Robertson
Ranch Hand

Joined: Nov 18, 2003
Posts: 91
I think you may have a problem in your formatter per the SimpleDateFormat doc here
it looks to me like hh as you have specified is for 1 - 12 (am/pm) and the HH is for 0 - 23. It appears your time actually uses 24 hour format.
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I updated it to HH and then added the seconds, so now it's
SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");

still got the same error.

Since I'm geting a log of what my dates evaluate to, that tells me the dates were set correctly, right?

Perhaps my problem lies elsewhere...
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
actually, now it works....


Thanks!
 
wood burning stoves
 
subject: date.after() problem
 
Similar Threads
[META/cxf/cxf.xml] cannot be opened because it does not exist
Weblogic 7.0 SSL Client
Calendar() / Date() bug ???
Convert String value to Date Object
Add days, but not weekend days