Suresh
Suresh

Reputation: 39531

new Date("05-MAY-09 03.55.50") is any thing wrong with this ? i am getting illegalArgumentException

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

is any thing wrong with this ? i am getting illegalArgumentException

Upvotes: 0

Views: 182

Answers (5)

Tom
Tom

Reputation: 45124

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");

Upvotes: 0

Robin
Robin

Reputation: 24272

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.

Upvotes: 0

z  -
z -

Reputation: 7178

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

Upvotes: 2

matt b
matt b

Reputation: 139971

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.

Upvotes: 14

RichieHindle
RichieHindle

Reputation: 281695

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

Upvotes: 1

Related Questions