java.text.ParseException: Unparseable date from ("d MMM yyyy kk:mm:ss zzz")

18.6k views Asked by At

I get ParseException in second line of the folowing code:

SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz");
Date response = formatter.parse(dateStr);

Exception:

java.text.ParseException: Unparseable date: "1 Dec 2014 08:32:59 GMT" (at offset 2)

How to solve this?

2

There are 2 answers

0
Ruchira Gayan Ranaweera On BEST ANSWER

You need to set the Locale.

SimpleDateFormat formatter = new SimpleDateFormat("d MMM yyyy kk:mm:ss zzz",
                                                                      Locale.US);
Date response = formatter.parse("1 Dec 2014 08:32:59 GMT");
System.out.println(response);
0
Kiryl Ivanou On

Why I receive java.text.ParseException: Unparseable date: "11 Jan 2015 15:56:00" (at offset 0) for 11 Jan 2015 15:56:00 +0100?!

SimpleDateFormat dateFormat = null;
                Date pubDate = null;
                try {
                    dateFormat = new SimpleDateFormat(
                            "EEE dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
                    pubDate = dateFormat.parse(this.pubDate);
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                dateFormat = new SimpleDateFormat("dd/MM/yyy");
                // convert to format dd/mm/yyyy
                this.pubDate = dateFormat.format(pubDate);

Thank you so much!