title: XMLGregorianCalendar date format 'dd/MM/yyyy HH:mm:ss.SSS'
body: <pre><code>String formatA ="yyyy-MM-dd'T'HH:mm:ss'Z'";
  String formatB = "dd/MM/yyyy HH:mm:ss.SSS";
  try {
      XMLGregorianCalendar gregFmt = DatatypeFactory.newInstance().newXMLGregorianCalendar(new SimpleDateFormat(formatB).format(new Date()));
      System.out.println(gregFmt);
  } catch (DatatypeConfigurationException e) {
  };
  </code></pre>
  
  <p>I am trying to formate XMLGregorianCalendar date .
  The above code formats well for format <code>"yyyy-MM-dd'T'HH:mm:ss'Z'"</code></p>
  
  <p>But for  formatB <code>dd/MM/yyyy HH:mm:ss.SSS</code>    it throws error</p>
  
  <pre><code>java.lang.IllegalArgumentException
  </code></pre>
  
  <p>Do advice on how to fix it.  Thank you so much!</p>
  
  <p>log</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: 23/08/2017 16:13:04.140
  at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parseAndSetYear(XMLGregorianCalendarImpl.java:2887)
  at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(XMLGregorianCalendarImpl.java:2773)
  at com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.&lt;init&gt;(XMLGregorianCalendarImpl.java:435)
  at com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(DatatypeFactoryImpl.java:536)
  at test.test.main(test.java:19)
  </code></pre>
  
  <p>line19 is line 4 , in the above code 'XMLGregorianCalendar gregFmt...'</p>