1

Getting a DateTimeParseExcpetion when trying to convert a String 2019-08-13T07:29:12.000+0000 into an OffsetDateTime. The String comes from SalesForce

OffsetDateTime.parse("2019-08-13T07:29:12.000+0000", DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.systemDefault()))
Sweeper
  • 213,210
  • 22
  • 193
  • 313
Alec
  • 13
  • 1
  • 3
  • May be seen as duplicate of [Convert date into AEST using java](https://stackoverflow.com/questions/48412345/convert-date-into-aest-using-java) – Ole V.V. Aug 23 '19 at 17:12

1 Answers1

3

You could use a custom formatter matching to the specific format provided by Salesforce. In this case, you could try as shown below

 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
 OffsetDateTime.parse("2019-08-13T07:29:12.000+0000", formatter);

More details about formatter could be found https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

Vinoth A
  • 1,099
  • 9
  • 10