public static Instant toInstant ( String dateTimeString ) throws ParseException { if ( dateTimeString == null ) { return ( null ) ; } dateTimeString = dateTimeString . trim ( ) ; if ( dateTimeString . endsWith ( "Z" ) ) { return ( Instant . parse ( dateTimeString ) ) ; } else { // Convert UTC zoned dates to 0 offset date if ( dateTimeString . endsWith ( "UTC" ) ) { dateTimeString = dateTimeString . replace ( "UTC" , "+0000" ) ; } OffsetDateTime odt = ( dateTimeString . length ( ) > 25 ? OffsetDateTime . parse ( dateTimeString , ODT_WITH_MSEC_PARSER ) : OffsetDateTime . parse ( dateTimeString , ODT_PARSER ) ) ; return ( odt . toInstant ( ) ) ; } }
Parses an ISO8601 formatted string a returns an Instant instance .