I’m using SimpleDateFormat with the pattern EEE MM/dd hh:mma, passing in the date String Thu 10/9 08:15PM and it’s throwing an Unparseable date exception. Why? I’ve used various patterns with SimpleDateFormat before so I’m fairly familiar with its usage. Maybe I’m missing something obvious from staring at it too long.
The other possibility is funky (technical term) whitespace. The context is a screen-scraping app, where I’m using HtmlCleaner to tidy up the messy html. While I’ve found HtmlCleaner to be pretty good overall, I’ve noticed strange issues with characters that look like whitespace but aren’t recognized as such with a StringTokenizer, for example. I’ve mostly worked around it and haven’t dug into the character encoding or anything like that but am starting to wonder.
To test if it’s the date format, write a test class to prove it out. For these types of things, I like to use bsh (beanshell). Here was my test:
Which outputted: Fri 10/09 08:15PM
So, at least with my jdk / jre version (1.6), the format strings seem to work just fine. i think the next step is to make sure the string you’re dealing with is exactly what you think it is. Can you add logging to your code, and dump out the input string to a log file? Then you could look at it in a nice text editor, run it through your test class, or look at it in a hex editor to make sure that it’s just normal text.
Good luck!