@@ -0,0 +1,1857 @@
+package ieg.util.xml;%0D%0A%0D%0Aimport java.util.Date;%0D%0Aimport java.util.GregorianCalendar;%0D%0A%0D%0Aimport javax.xml.datatype.DatatypeConfigurationException;%0D%0Aimport javax.xml.datatype.DatatypeFactory;%0D%0A%0D%0A/**%0D%0A * Convert date time object to and from a XML compliant string.%0D%0A * %0D%0A * %3Cp%3E%0D%0A * The date format is closely related to the dates and times described in ISO%0D%0A * 8601 (see %3Ca href=%22http://www.w3.org/TR/xmlschema-2/#dateTime%22%3EXML Schema 1.0%0D%0A * Part 2, Section 3.2.7%3C/a%3E). Internally, %7B@link DatatypeFactory%7D is used,%0D%0A * because this format is not supported by %7B@link java.text.SimpleDateFormat%7D.%0D%0A * Further alternatives would be JodaTime or%0D%0A * %7B@link javax.xml.bind.DatatypeConverter%7D.%0D%0A * %0D%0A * %3Cp%3E%0D%0A * Instances of this class are not safe for use by multiple threads.%0D%0A * %0D%0A * @author Rind%0D%0A * %0D%0A */%0D%0Apublic class XmlCalendarConverter %7B%0D%0A%0D%0A    private GregorianCalendar cal;%0D%0A    private DatatypeFactory factory;%0D%0A%0D%0A    public XmlCalendarConverter() throws DatatypeConfigurationException %7B%0D%0A        factory = DatatypeFactory.newInstance();%0D%0A        cal = new GregorianCalendar();%0D%0A    %7D%0D%0A%0D%0A    public String toXML(long millis) %7B%0D%0A        cal.setTimeInMillis(millis);%0D%0A        return toXML(cal);%0D%0A    %7D%0D%0A%0D%0A    public String toXML(Date date) %7B%0D%0A        cal.setTime(date);%0D%0A        return toXML(cal);%0D%0A    %7D%0D%0A%0D%0A    public String toXML(GregorianCalendar cal) %7B%0D%0A        return factory.newXMLGregorianCalendar(cal).toXMLFormat();%0D%0A    %7D%0D%0A%0D%0A    public GregorianCalendar toCalendar(String xml)%0D%0A            throws IllegalArgumentException %7B%0D%0A        return factory.newXMLGregorianCalendar(xml).toGregorianCalendar();%0D%0A    %7D%0D%0A%0D%0A    public Date toDate(String xml) %7B%0D%0A        cal = toCalendar(xml);%0D%0A        return cal.getTime();%0D%0A    %7D%0D%0A%0D%0A    public long toTimeInMillis(String xml) %7B%0D%0A        cal = toCalendar(xml);%0D%0A        return cal.getTimeInMillis();%0D%0A    %7D%0D%0A%7D%0D%0A

Convert date time object to and from a XML compliant string using DatatypeFactory