我有代码片段,它在 scala 和 java 中给出不同的输出。我想要与Java相同的输出,请任何人指导。
Java2012-12-13T10:36:38
中的输出: 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());
}
}