Java – joda datetime format for xmlregionancalendar type

I use JAXB 2.2 8-b01 impl, I have a schema, which has an XS: date element, which creates an xmlregionancalendar instance I tried to get the joda time datetime timestamp format, but since I had to have an xmlregionancalendar instance, I didn't know if it was possible Any ideas?

Schema XSD:

<xs:element type="xs:date" name="date-archived" minOccurs="0" maxOccurs="1" nillable="false"/>

JAXB generated properties:

XmlSchemaType(name = "date")
    protected XMLGregorianCalendar date;

XML conversion class:

//java. util. Date is being passed

private XMLGregorianCalendar converToGregorianCal(Date date) {
        DatatypeFactory df = null;
        try {
          df = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
          LOG.error("error getting DatatypeFactory instance " + e.getMessage()); 
        }
        if (date == null) {
          return null;
        } else {
          GregorianCalendar gc = new GregorianCalendar();
          gc.setTimeInMillis(date.getTime());
          return df.newXMLGregorianCalendar(gc);
        }
      }

Solution

This is a short approach:

public DateTime convert(final XMLGregorianCalendar xmlgc) {
    return new DateTime(xmlgc.toGregorianCalendar().getTime());
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>