The thing i want to do is get a Date object from a date-string. I get the date-string from a file, and there are different date-formats (yyyy, yyyy-MM, yyyy-MM-dd, etc.). So the problem is that the string i read from the file can be any of these formats. That's why i try to match the date-string against a certain format.
So if i enter a date-string like this one: "2007-05-15T15:57:23", it would return a Date object with 2007 as year, 05 as month, 15 as day, 15 as hour, 57 as minutes and 23 as seconds. But if i enter "2007-05-15" it would only return a Date object with 2007 as year, 05 as month and 15 as day.
Atm, when i enter "12/" which is an invalid date-pattern, it still matches the "yyyy" pattern, so that's basically my problem.
If you know an easier way to accomplish this, do let me know. I could use regex though.
I tried using your code, exactly as you posted it, but it didn't seem to work. it prints:
Quote:
|
java.text.ParseException: Unparseable date: "12/"
|
Thanx for looking into it