0

I have a String that contains a date.

I'm trying to do so but it gives me an error.

java.text.ParseException: Unparseable date: "Fri Mar 20 20:44:49 CET 2015" (at offset 0)
at java.text.DateFormat.parse(DateFormat.java:626)

I'm trying this.

String fechaFestivo = c.getString(1);//Fri Mar 20 20:44:49 CET 2015

SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Date date = format.parse(fechaFestivo);
3
  • 1
    Try this DateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy", Locale.ENGLISH); Commented Mar 24, 2015 at 10:50
  • @Skizo Did you try your solution? It isn't work... Commented Mar 24, 2015 at 10:54
  • I tried your solution (as well as the one of @Skizo) and both are working for me (only change is that I hardcoded Fri Mar 20 20:44:49 CET 2015). Are you sure about fechaFestivo string ? Commented Mar 24, 2015 at 10:59

3 Answers 3

3

Your SimpleDateFormat is using the default locale, which may not be English. In that case, the abbreviated name of the day will not be recognized.

Make sure to use the correct locale with this constructor:

SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy", Locale.US);
Sign up to request clarification or add additional context in comments.

Comments

1

Try to replace your SimpleDateFormat for DateFormat, something like that :

String fechaFestivo = c.getString(1); //Fri Mar 20 20:44:49 CET 2015

DateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy", Locale.ENGLISH);
Date date = format.parse(fechaFestivo);

Comments

0

Use "EEE MMM dd HH:mm:ss zzz yyyy"

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.