Removing "Z" part from XMLGregorianCalender

Rajkishan Swami picture Rajkishan Swami · May 18, 2015 · Viewed 11.9k times · Source

When I do like below,

GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.setTime(startTime);  // startTime Date
DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);

I get Output like 2015-04-15T11:04:30.000Z.

I want it to be like 2015-04-15T11:04:30.000.

Is there a way to achieve this?

Answer

Ignas Vaitekunas picture Ignas Vaitekunas · Feb 15, 2016

Accepted answer or my Java seems to be outdated because I received this error: The method newXMLGregorianCalendar(String) in the type DatatypeFactory is not applicable for the arguments (SimpleDateFormat)

and I didn't want to extend, so I solved it by removing timezone:

    xmlCalendar.setTimezone(DatatypeConstants.FIELD_UNDEFINED);