0

我在以下代码的第二行得到 ParseException:

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

例外:

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

如何解决这个问题?

4

2 回答 2

1

您需要设置语言环境。

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);
于 2014-12-01T09:15:35.783 回答
0

为什么我收到 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);

太感谢了!

于 2015-01-14T18:37:38.860 回答