I use JAXB for un/marshaling XML messages which I get from server. Usually I get the XMLGregorianCalendar values in the fields, that are defind as xs:dateTime in the describing XSD files, so the conversion to XMLGregorianCalendar is done automatically by JAXB.
Example from XSD file
<xs:attribute name="readouttime" use="required" type="xs:dateTime" />
However one field is defined as xs:string like this:
<xs:element minOccurs="1" maxOccurs="1" name="Value" type="xs:string" />
but I am receiving a value that should represent the dateTime:
<Value>2014-08-31T15:00:00Z</Value>
Is there any nice way, how to convert this string to XMLGregorianCallendar, or should I use SimpleDateFormat and type the pattern manually? I feel this may be a dangerous part.
A quick Google search yields
String mydatetime = "2011-09-29T08:55:00";
XMLGregorianCalendar xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(mydatetime);
Credits go to this blog post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With