I have the below method,
public static XMLGregorianCalendar stringToXMLGregorianCalendar(String s)
throws ParseException,
DatatypeConfigurationException
{
XMLGregorianCalendar result = null;
Date date;
SimpleDateFormat simpleDateFormat;
GregorianCalendar gregorianCalendar;
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
date = simpleDateFormat.parse(s);
gregorianCalendar =
(GregorianCalendar)GregorianCalendar.getInstance();
gregorianCalendar.setTime(date);
result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
return result;
}
It returns me 2014-04-29T13:22:51.000+05:30
but i dont want the timezone part and the milliseconds part as well. Is it possible to split its value and get it like 2014-04-29T13:22:51
. Any suggestion?
You have to set the timezone field part as undefined after you assign value to the result.
....
result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
result.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
return result;