Date contructor deprecation : Parsing a String to Date
807606Feb 7 2007 — edited Feb 7 2007Hi 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.