在我的应用程序中,我得到一个日期字符串'2017-08-08T07:32:24Z'我需要解析此字符串到目前为止。我已经为此编写了代码
String string = "2017-08-08T07:32:24Z";
DateFormat format = new SimpleDateFormat(" yyyy-MM-dd'T'HH:mm:ss'Z'");
Date date = format.parse(string);
执行代码时出现以下错误:
java.text.ParseException: Unparseable date: "2017-08-08T07:32:24Z"
at java.text.DateFormat.parse(Unknown Source)
at com.rapidvalue.accurate.utils.AutomationMail.getMailBodyData(AutomationMail.java:367)
at com.rapidvalue.accurate.utils.AutomationMail.sendMail(AutomationMail.java:205)
at com.rapidvalue.accurate.reporting.AutomationListener.onExecutionFinish(AutomationListener.java:1768)
at org.testng.TestNG.runExecutionListeners(TestNG.java:1158)
at org.testng.TestNG.run(TestNG.java:1123)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
可以对此有任何帮助
答案 0 :(得分:1)
请在yyyy之前删除splace。它应该工作。
String string = "2017-08-08T07:32:24Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
format.parse(string);