If you are on Java 1.4 or later, I would recommend using a regular expression. If 1.3 or below, just do a test for '-' or the length to figure it out.
Aside from being ugly, the try/catch blocks are misleading. Here a parse error is not an exception. It is something you are expecting to happen.
How are you handling the case where the user enters garbage like 'aaaa.' This may need to factor into your design decision.
Originally posted by Layne Lund:
where do these date entries come from?
Honestly, Jeanne Boyarsky, do you just search these forums for my posts so you can answer 'em?
I did consider what would happen if the user really entered some garbage data. Notice that the final "parse" isn't wrapped in it's own "try" block. If that one fails, it throws a ParseException and, likewise, so does the method this code is in (which, of course, you can't see ).