我正在尝试将 XMLGregorianCalendar 日期分配给 java.sql.Timestamp var,就像这样...
I'm trying to assign a XMLGregorianCalendar date to a java.sql.Timestamp var, like this...
var1.setTimeStamp(Timestamp.valueOf(var2.getXMLGregorianCalendar().toString()))
但显然,这不起作用,并引发异常...
But apparently, this is not working, and throws an exception...
java.lang.IllegalArgumentException: 时间戳格式必须是 yyyy-mm-dd hh:mm:ss[.fffffffff]
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
我也试过这个:
var1.setTimeStamp((Timestamp) var2.getXMLGregorianCalendar().getTime())
但是……
java.lang.ClassCastException: java.util.Date 不能转换为 java.sql.Timestamp
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
任何想法..?谢谢!
我找到了答案:
Timestamp timestamp = new Timestamp(var2.getXMLGregorianCalendar().toGregorianCalendar().getTimeInMillis());
var1.setTimeStamp(timestamp);
这篇关于将 XMLGregorianCalendar 转换为 java.sql.Timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!