1

How do i parse a date with the format 2020-12-31T11:46:18.000+00:00

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

Date startDate = sdf.parse("2020-12-31T11:46:18.000+00:00");

I get Unparseable date exception. I have tried providing the Z without the quote but still it throws the exception.

The below code also doesn't work

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Amit
  • 255
  • 2
  • 8
  • I strongly recommend taht you do not use `SimpleDateFormat` and `Date`. Those classes are troublesome and fortunately long outdated. Use `OffsetDateTime` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/index.html). Just `OffsetDateTime.parse("2020-12-31T11:46:18.000+00:00")` parses your string. You don’t even need to specify a formatter. – Ole V.V. Dec 06 '22 at 04:51

0 Answers0