Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Date contructor deprecation : Parsing a String to Date

807606Feb 7 2007 — edited Feb 7 2007
Hi All,

In Java 1.5 the Date() constructor Date(String s) is deprecated. As per the API Documentation DateFormat.Parse() method is used.

The following code from Java 1.4 version has to be upgraded to Java 1.5.

Existing Code:
Date dDate = new Date(sDate);

Modified Code:
DateFormat df = DateFormat.getDateInstance();
Date dDate = df.parse(sDate);

Here the DateFormat accepts a default formatting style as "Feb 01, 2007" and parses the String.

If the String sDate belongs to any other formatting style such as "01 Feb, 2007" or "01 Feb, 07" the code piece throws unparsable date error.

Please give your thougts on this issue to parse the string of any format..

Thanks,
Rajesh.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2007
Added on Feb 7 2007
22 comments
1,700 views