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?
Do it as follow
DatatypeFactory df;
try {
df = DatatypeFactory.newInstance();
return df.newXMLGregorianCalendar(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
} catch (DatatypeConfigurationException e) {
// throw new SomeRuntimeException(e);
}
Or Extend new class from XMLGregorianCalendar
, override toXMLFormat
and then delegate ALL the other methods to the contained instance.
class CustomXMLGregorianCalendar extends XMLGregorianCalendar
{
XMLGregorianCalendar calendar;
CustomXMLGregorianCalendar(XMLGregorianCalendar calendar){
this.calendar = calendar;
}
public String toXMLFormat() {
String text = calendar.toXMLFormat();
int pos = text.indexOf('Z');
return pos < 0 ? text : text.substring(0,pos);
}
public void setTimezone(int offset){ calendar.setTimezone( offset ); }
// ...
}