java.text.ParseException:来自(" d MMM yyyy kk:mm:ss zzz")的无法解析的日期

时间:2014-12-01 09:11:36

标签: java simpledateformat parseexception

我在以下代码的第二行中得到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)

如何解决这个问题?

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

我收到的原因 java.text.ParseException:无法解析的日期:“2015年1月11日15:56:00”(偏移0处) 2015年1月11日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);

非常感谢你!

相关问题