Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    If the string is in the instant format, with trailing Z as offset, we don’t need to specify this explicitly. Just Instant i = Instant.parse(s);. The string in the question had +01:00, in which case DateTimeFormatter.ISO_INSTANT does not work (at least not on my Java 11). Commented Feb 14, 2020 at 2:37
  • 5
    @OleV.V. You can use ISO_OFFSET_DATE_TIME to format dates with offsets, like +01:00 (docs.oracle.com/javase/8/docs/api/java/time/format/…) Commented Mar 16, 2020 at 14:30
  • 1
    That’s true, @LucasBasquerotto. Though not mentioning that formatter explicitly, the answers by Adam and by Basil Bourque already do something similar. Commented Mar 16, 2020 at 14:38
  • 3
    This cannot parse "2020-06-01T14:34:00-05:00" which is a string produced by Javascript's toISOString() method. Commented Jun 11, 2020 at 19:50