public static Date parseISO8601DateString ( String source ) { final String [ ] supportedFormats = new String [ ] { "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" , "yyyy-MM-dd'T'HH:mm:ssXXX" , "yyyy-MM-dd'T'HH:mm:ssZ" , "yyyy-MM-dd'T'HH:mm:ss.SSSZ" } ; // SimpleDateFormat is not fully ISO8601 compatible, so we replace 'Z' by +0000 if ( StringUtils . contains ( source , "Z" ) ) { source = StringUtils . replace ( source , "Z" , "+0000" ) ; } Date parsedDate = null ; for ( final String format : supportedFormats ) { try { parsedDate = new SimpleDateFormat ( format ) . parse ( source ) ; } catch ( ParseException pe ) { } if ( parsedDate != null ) { return parsedDate ; } } return null ; }
Try to parse source string as a ISO8601 date .