tags:

views:

106

answers:

5
new Date("05-MAY-09 03.55.50")

is any thing wrong with this ? i am getting illegalArgumentException

+1  A: 

Use colons to separate hours, minutes and seconds: "05-MAY-09 03:55:50"

RichieHindle
A: 

That constructor is deprecated (since jdk 1.1).

It not even valid in java5

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html

You should

SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
Date date = sdf.parse("05-MAY-09 03:55:50");
Tom
Unless you meant this as pseudo-code, it won't compile since parse() is not a static method
matt b
yes, i meant pseudocode. As shown in http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html
Tom
+14  A: 

That Date constructor is deprecated for a reason.

You should be using a DateFormat / SimpleDateFormat instead to create Date instances from a String representation.

DateFormat df = new SimpleDateFormat("dd-MMM-yy hh.mm.ss");
Date myDate = df.parse("05-05-MAY-09 03.55.50");

This way, you can parse dates that are in just about any format you could conceivably want.

matt b
+2  A: 

Other than the fact that you are using a deprecated method (you should be using SimpleDateFormat instead), this should work:

    new Date("05-MAY-09 03:55:50");

Also check out Joda Time

yx
And the Joda Time requrement has been fulfilled! http://stackoverflow.com/questions/835418/what-are-the-stackoverflow-standard-answers-closed
Paul Tomblin
A: 

Don't use this method, as it has been deprecated for years (and years). Use DateFormat.parse() in which you can easily define the format you want to parse.

Robin