Code example for DatatypeFactory

Methods: newXMLGregorianCalendar

0
     * @return the parse date 
     * @throws IllegalArgumentException if the provided string does not conform to ISO-8601 
     */ 
    public static Date fromISO8601(String pDateString) {
        if (datatypeFactory != null) {
            return datatypeFactory.newXMLGregorianCalendar(pDateString.trim()).toGregorianCalendar().getTime();
        } else { 
            try { 
                // Try on our own, works for most cases 
                String date = pDateString.replaceFirst("\\+(0\\d)\\:(\\d{2})$", "+$1$2");
                date = date.replaceFirst("Z$","+0000");
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                return dateFormat.parse(date);
            } catch (ParseException e) {
                throw new IllegalArgumentException("Cannot parse date '" + pDateString + "': " +e,e);
            } 
        } 
    } 
 
    /**