Parsing ISO 8601 String without Colon in Offset to Java 8 Date
The issue arises when attempting to parse an ISO 8601-formatted string with an offset lacking a colon (e.g., "2018-02-13T10:20:12.120 0000") using the new date-time API in Java 8.
Solution
Until bug is fixed (Java 8)
Use a workround:
<code class="java">String input = "2018-02-13T10:20:12.120+0000".replace( "+0000" , "+00:00" ); OffsetDateTime odt = OffsetDateTime.parse( input );</code>
<code class="java">String input = "2018-02-13T10:20:12.120+0000" ; DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuu-MM-dd'T'HH:mm:ss.SSSX" ); OffsetDateTime odt = OffsetDateTime.parse( input , f );</code>
When bug is fixed:
To parse without workarounds:
<code class="java">OffsetDateTime odt = OffsetDateTime.parse( "2018-02-13T10:20:12.120+0000" );</code>
Additional Notes:
The above is the detailed content of How to Parse ISO 8601 String with Missing Colon in Offset in Java 8?. For more information, please follow other related articles on the PHP Chinese website!