I have code snippet which is giving different output in scala and java. I want the same output as in Java, any one please guide.
Output in Java: 2012-12-13T10:36:38
Output in Scala: 2012-12-13T10:35:38.000+04:00
/**
* Convert the datetime to XMLGregorianCalendar datetime format.
* <br><h6>Example Date format You have to Give is : </h6>
* new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(Calendar.getInstance().getTime()))
* <br>1900-01-01T00:00:00
*/
public static XMLGregorianCalendar stringToXMLGregorianCalendar(String datetime) throws Exception {
try {
if(datetime == null || "".equals(datetime))
return null;
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
gc.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(datetime));
return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
} catch (DatatypeConfigurationException e) {
logger.error(e.fillInStackTrace());
throw new Exception(e.fillInStackTrace());
}
}
I have solved the problem please find the solution below.
I have set the timezone and millisecond to undefined in the above code.
xgc.setMillisecond(DatatypeConstants.FIELD_UNDEFINED)xgc.setTimezone(DatatypeConstants.FIELD_UNDEFINED)