我正在将 java.util.Date 转换为 XMLGregorianDate。
当我在控制台上打印 My util date 时,它显示:
Date: 2011-01-25 20:33:46.54
但是在转换之后,当我尝试使用它时,出现以下异常: org.springframework.ws.soap.client.SoapFaultClientException:月份字段的值 0 无效。
Code for Date conversion is:
DatatypeFactory df = null;
try {
df = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(account.getCreationDate().getTime());
method returns: df.newXMLGregorianCalendar(gc);
同样有趣的是,当我显示 util Date.getYear() 和 getMonth() 方法(仅用于在控制台上显示日期的弃用方法)时,控制台上的输出是:
Year: 111 Month: 0
为什么会这样?谁能说出这背后的原因? 提前谢谢你。
最佳答案
XMLGregorianCalendar
,即使我没有在示例中看到它,也使用基于 1 的月份数字。与 java.util.Calendar
类不同,后者使用基于 0 的月份数字。
关于java - 月份字段的值 0 无效。将 util.date 转换为 XMLgregoriandate 时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5509704/