A simple method to converting a java Date to a XMLGregorianCalendar (a representation of W3C XML Schema 1.0 date/time):

public static XMLGregorianCalendar dateToXmlGregorianCalendar(Date date)
    {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(date);
        try
        {
            return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        }
        catch (DatatypeConfigurationException e)
        {
            return null;
        }
    }

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *