Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting String to Date in java

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?

like image 531
omar Avatar asked Jan 22 '26 06:01

omar


1 Answers

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);
like image 102
Reimeus Avatar answered Jan 24 '26 19:01

Reimeus