Hi, please find the below program iam getting the exception
Basically iam try to the format the string , this string should be different date pattern.
Iam getting the following exception :-
Exception in thread "main" java.lang.IllegalArgumentException
at java.util.Date.parse(Unknown Source)
at java.util.Date.<init>(Unknown Source)
If i use try catch block iam getting the compilation error
StringToDate.java:17: exception java.text.ParseException is never thrown in body
of corresponding try statement
If the number is followed by whitespace, a comma, a hyphen, or end of string, then if an hour has been recognized but not a minute, it is regarded as a minute; otherwise, if a minute has been recognized but not a second, it is regarded as a second; otherwise, it is regarded as a day of the month.
The first item in the Array is interpreted to be hour minute and second and thus an exception is thrown.
Sridhar Ranganthan wrote:can any one please help me to resolve this program.
What is exactly the problem you are trying to solve?
Your program parses strings into Date objects. It expects the strings to be in the format "dd/MM/yyyy". Then you put in strings with different formats. Obviously if the string doesn't match the format, you get an exception - that's to be expected.
So, what are you looking for, a program that can parse all those different strings in different formats?
You can catch the ParseException and try to parse the string with a different format, until it parses without an exception.