SimpleDateFormat:不可解析的日期异常

Nil*_*ste 7 java android date-format simpledateformat parseexception

在查看了几个现有帖子之后,我仍然无法使我的SimpleDateFormat解析器工作.这是代码:

SimpleDateFormat df = new SimpleDateFormat(
    "EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
try {
    volcanoListDate = df.parse(currentValue);
} catch (ParseException e) {
    Log.d("DEBUG", e.toString());
    Log.d("DEBUG", currentValue);
}
Run Code Online (Sandbox Code Playgroud)

我总是以ParseException结束.以下是调试消息的输出:

06-09 23:52:17.478:DEBUG/DEBUG(2436):java.text.ParseException:Unparseable date:06-09
23:52:17.478:DEBUG/DEBUG(2436):Wed,08 Jun 2011 03:23: 55 -0500

区域设置已设置,模式看起来没问题.我哪里错了?

Nil*_*ste 4

这是解决方案:

            SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
        try {
            volcanoListDate = df.parse(currentValue.replaceAll("\\p{Cntrl}", ""));
        } catch (ParseException e) {
            Log.d("VOLCANO_DEBUG", e.toString());
            Log.d("VOLCANO_DEBUG", currentValue);
        }
Run Code Online (Sandbox Code Playgroud)

重要的更改是.replaceAll("\\p{Cntrl}", ""),它从解析的字符串中删除控制字符。奇怪的是,我在字符串所在的 xml 中用 Notepad++ 没有看到任何这些字符。然而,显然有一些东西现在正在发挥作用。

感谢您的帮助!