1

Hello I have ParseException when I try to use SimpleDateFormat:

this.firstTweetTime = new SimpleDateFormat("mm/dd/yyyy HH:mm",Locale.US).parse(array[4]);

where array[4] is a string from text file I read and it is like this: 12/8/2010 11:48

I get the following error: enter image description here I cannot understand what went wrong. can you please help me.

3
  • 1
    It looks like you've read the data from the file using the wrong character encoding. Commented May 19, 2016 at 13:09
  • At least one error is inside your pattern. You should use "MM/dd/yyyy HH:mm" using "MM" for month number. It might also be necessary to change the locale because the text might contain non-ascii-digits (not quite clear from your description). Commented May 20, 2016 at 11:53
  • @Meno yes you are right, but that was not the problem. in fact this should not even fire parse exception Commented May 20, 2016 at 12:37

2 Answers 2

1

it looks like the date you are getting from your array has some characters that SimpleDateFormat cannot understand, put array[4] in a logger or another line where you can debug and see exactly what you are trying to parse.

Sign up to request clarification or add additional context in comments.

Comments

0

The reason why I had such exception was not related to Date Format rather that it was related to the source text file itself. turns out that the file was saved as unicode format while it should be saved as UTF-8 format. that's the reason why the data looked corrupt in the exception while I can read it from the file normally it was not processed through my application.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.