0

2017-08-01T05:08:51.000Z

I'm trying to parse the above date string using below code. It says unparseable date at offset 23. I can't seem to figure out the issue.

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            Date date = null;
            try {
                date = format.parse("2017-08-01T05:08:51.000Z");
            } catch (ParseException e) {
                e.printStackTrace();


  }
Chinmay jain
  • 979
  • 1
  • 9
  • 20
LEE
  • 3,335
  • 8
  • 40
  • 70
  • Try this: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'. Put an apostrophe around Z. – Igorovics Aug 01 '17 at 13:21
  • 1
    Or better, use `X` to mean "ISO-8601 UTC offset" - that way I'd hope it would avoid using the system time zone... – Jon Skeet Aug 01 '17 at 13:22
  • @Igorovics you should use the X letter, see https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html – jontro Aug 01 '17 at 13:22

1 Answers1

0

Thanks guys. Yes, so the correct format should be "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

LEE
  • 3,335
  • 8
  • 40
  • 70