No, it is not possible. The whole point in XMLGregorianCalendar
is to provide dates and times in a format required by XML, and the format you are asking about is not allowed in XML. So what you are asking for is prevented on purpose.
If your requirement is an XMLGregorianCalendar
, then you will have to live with the format printed from its toString
and toXMLFormat
methods (the two return the identical strings). I also don’t see why you should not be happy with that. This format fulfils the XML specification.
PS While toString()
and toXMLFormat()
return strings in XML format, i consider it wrong to say that the XMLGregorianCalendar
has got this format. Its internal representation is quite different (and nothing we should care about). I consider it more correct to say that an XMLGregorianCalndar
cannot have a format.
Link: An answer of mine treating more thoroughly why you can have no date-time object with a format. I am using Date
as an example, but what I write is fully valid for XMLGregorianCalendar
too, and I do mention XMLGregorianCalendar
at the end.