Reputation: 101
I have used SimpleDateFormat to parse Strings into Dates many times in the past, but today I ran across an error that I cannot seem to see. I am parsing a csv, and I have this:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = dateFormat.parse(nextLine[0]);
I get this error
java.text.ParseException: Unparseable date: "2011-06-17 21:43:17.493"
It looks to me like the format matches the string when referencing the javadoc for SimpleDateFormat here: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
am I missing something with SimpleDateFormat?
Upvotes: 1
Views: 616
Reputation: 1350
Nothing is worng with your code. You just have invisible symbols at this line
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
You probably copied it from a PDF file or other source that inject that symbols into your text.
Try to copy it manually and it will be fine. It work for me after I done so.
Upvotes: 3