Java WebService把Date类型转换成XMLGregorianCalendar
JavaEE 的WebService中的Date类型在Web应用中调set方法的时候,默认情况下,JAXB将xsd:date, xsd:time, 和xsd:dateTime映射为XMLGregorianCalendar; 下面是将Date转换成XMLGregorianCalendar的方法:
GregorianCalendar cal = new GregorianCalendar(); cal.setTime(UtilTools.getCurrentDate()); XMLGregorianCalendar gc = null; gc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); vo.setAddTime(gc);