3

I am programming in java, and have a little problem since yesterday in parsing Date (converting from String to Date).

I am getting this exception :

java.text.ParseException: Unparseable date: "Fri May 24 18:47:31 GMT+01:00 2013"

Here is my code:

String db= obj.getDebut(); // = "Fri May 24 18:47:31 GMT+01:00 2013"
String pattern2 = "EEE MMM d HH:mm:ss ZZZZ yyyy";
Date datedebutEntree = new SimpleDateFormat(pattern2).parse(db);    

Can anyone tell me what I'm doing wrong?

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
omar
  • 33
  • 2
  • 3
    that was a problem in application language , i added locale.ENGLISH and that w orked , thank yoou for your help – omar May 18 '13 at 18:22

2 Answers2

4

Your application language appears to be French. If your default Locale is likewise, it will throw a ParseException when attempting to parse English day and month fields. Use Locale.ENGLISH instead:

String pattern2 = "EEE MMM d HH:mm:ss Z yyyy";
Date datedebutEntree = new SimpleDateFormat(pattern2, Locale.ENGLISH).parse(db);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

You don't need to repeat the Z pattern. Use this:

String pattern2 = "EEE MMM d HH:mm:ss Z yyyy";
likeitlikeit
  • 5,563
  • 5
  • 42
  • 56