我收到了这个错误。
我的代码出了什么问题?
String line = "Date: Mon, 22 Aug 2005 20:21:52 +0200";
String datestring = line.substring(6);
DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss ZZZZZ");
Date inputDate = null;
try {
inputDate = dateFormat.parse(datestring);
} catch (ParseException e) {
e.printStackTrace();
}
我的错误日志:
java.text.ParseException:Unparseable date:" Mon,22 Aug 2005 20:21:52 + 0200"在netspy.EMail.parseLine(EMail.java:133)的java.text.DateFormat.parse(未知来源) netspy.EMail.parseMail(EMail.java:91)at netspy.FileManager.findMails(FileManager.java:66)at netspy.BaseFrame.switchContent(BaseFrame.java:218)at netspy.BaseListener.actionPerformed(BaseListener.java:79)at javax.swing.AbstractButton.fireActionPerformed(未知来源)at javax.swing.AbstractButton $ Handler.actionPerformed(Unknown Source)at javax.swing.DefaultButtonModel.fireActionPerformed(未知来源)at javax.swing.DefaultButtonModel.setPressed(未知来源)at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(未知 来自)java.awt.Component.processMouseEvent(未知来源)at javax.swing.JComponent.processMouseEvent(未知来源)at java.awt.Component.processEvent(未知来源)at java.awt.Container.processEvent(未知来源)at java.awt.Component.dispatchEventImpl(未知来源)at java.awt.Container.dispatchEventImpl(未知来源)at java.awt.Component.dispatchEvent(未知来源)at java.awt.LightweightDispatcher.retargetMouseEvent(未知来源)at java.awt.LightweightDispatcher.processMouseEvent(未知来源)at java.awt.LightweightDispatcher.dispatchEvent(未知来源)at java.awt.Container.dispatchEventImpl(未知来源)at java.awt.Window.dispatchEventImpl(未知来源)at java.awt.Component.dispatchEvent(未知来源)at java.awt.EventQueue.dispatchEventImpl(未知来源)at java.awt.EventQueue.access $ 400(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知 来源)at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知 来自)java.awt.EventQueue $ 4.run(未知来源)at java.awt.EventQueue $ 4.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知 来自)java.awt.EventQueue.dispatchEvent(未知来源)at java.awt.EventDispatchThread.pumpOneEventForFilters(未知来源) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 在java.awt.EventDispatchThread.pumpEventsForHierarchy(未知 来自java.awt.EventDispatchThread.pumpEvents(未知来源) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)at java.awt.EventDispatchThread.run(未知来源)
答案 0 :(得分:8)
您的系统区域设置是否不是英文?尝试明确指定语言环境:
DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss ZZZZZ",
Locale.US);