New date ("05-MAY-09 03.55.50") - is there something wrong with that? i am getting illegalArgumentException

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

      

is there something wrong with that? I am getting illegal_ArgumentException

0


a source to share


5 answers


Do not use this method as it has been deprecated for many years (and years). Use DateFormat.parse () where you can easily define the format you want to parse.



0


a source


That the Date constructor is deprecated for some reason.

You should use DateFormat / SimpleDateFormat instead to create Date instances from 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 almost any format you might want.

+14


a source


Apart from using the deprecated method (you must use SimpleDateFormat ) this should work:

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

      

Also check out Joda Time

+2


a source


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

+1


a source


This constructor is deprecated (since jdk 1.1).

This is not even relevant 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");

      

0


a source







All Articles