-2

In my application i got a date string has '2017-08-08T07:32:24Z' i need to parse this string to date. I have written a code for that

        String string = "2017-08-08T07:32:24Z";
        DateFormat format = new SimpleDateFormat(" yyyy-MM-dd'T'HH:mm:ss'Z'");
        Date date = format.parse(string);

on executing the code i got the below error :

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)

can any one help on this

Jens
  • 67,715
  • 15
  • 98
  • 113
Nikhil Surendran
  • 956
  • 4
  • 14
  • 25

1 Answers1

1

Please remove the splace before yyyy. It should work.

String string = "2017-08-08T07:32:24Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
format.parse(string);
Chetan chadha
  • 558
  • 1
  • 4
  • 19