How to subtract one day in XMLGregorianCalendar? Also while subtracting how to cope up with following problems :
and other similar stuffs.
Please do not suggest to use any other library like Joda-Time. I know they are great, but I need to get this done using XMLGregorianCalendar only.
Thanks
Just convert to a normal GregorianCalendar
, do the arithmetic there, then convert back:
GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
calendar.add(Calendar.DAY_OF_MONTH, -1);
xmlCalendar = datatypeFactory.newXMLGregorianCalendar(calendar);
(This assumes you already have a DatatypeFactory
of course. You can always call DatatypeFactory.newInstance()
if necessary.)
See more on this question at Stackoverflow