
05-15-07, 06:20 PM
|
|
Community VIP
|
|
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by UnrealEd
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:
Thanx for looking into it
|
I thought you wanted a parse exception to occur when 12/ is entered? I'll take a look at matching the strings exactly a little latter tomorrow....
|