Date to XMLGregorianCalendar

XMLGregorianCalendar is a representation for W3C XML Schema 1.0 date/time datatypes. The XML Schema standard specifies very precise rules about the functionality and representation of dates in XML which is doesn't match existing date classes in the JDK. This example will show how to convert a date to a XMLGregorianCalendar.

Straight up Java

public void convert_date_to_XMLGregorianCalendar()
        throws DatatypeConfigurationException {

    GregorianCalendar gCalendar = new GregorianCalendar();

    XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory