3

for some unknown reason this code throws an Unparseable date exception

Any ideas how to solve this issue?

Thanks!

import java.text.DateFormat
import java.text.SimpleDateFormat

String dateString  =                       "Sat Nov 02 2013 00:15:00"

SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss");
Date result =  df.parse(dateString);
System.out.println(result);

Screenshot how this code is run

enter image description here

user955732
  • 1,330
  • 3
  • 21
  • 48
  • 3
    Why post code that won't compile? It gives the impression you didn't really try it, and makes it harder for people to help you. – T.J. Crowder Nov 03 '13 at 16:53
  • Thanks for your remarks, I added a screenshot how the code is compiled an run. GroovyConsole is an excellent tool for running java snippets. There are many many posts about date parsing problems using, but I couldn't find one with short notice that solved this particular problem. – user955732 Nov 03 '13 at 17:03
  • @user955732 That may be, but this is not a standard tool used by those who answer questions. This is why it is recommended to post an [SSCCE](http://sscce.org/) – Reimeus Nov 03 '13 at 17:09

1 Answers1

6

The constructor you're using use the default date format symbols for your default Locale.

I suppose that your default Locale doesn't spell months in English. Hence, you should specify an English one :

SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss", Locale.US);

Output (with a fr_FR default Locale):

Sat Nov 02 00:15:00 CET 2013

Alexis C.
  • 91,686
  • 21
  • 171
  • 177