java.util.Date to XMLGregorianCalendar

2022-08-31 04:10:45

难道没有一种方便的方法从java.util.Date到XMLGregorianCalendar吗?


答案 1
GregorianCalendar c = new GregorianCalendar();
c.setTime(yourDate);
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

答案 2

对于那些可能最终在这里寻找相反转换(从到)的人:XMLGregorianCalendarDate

XMLGregorianCalendar xcal = <assume this is initialized>;
java.util.Date dt = xcal.toGregorianCalendar().getTime();