java.util.Date to XMLGregorianCalendar

mac picture mac · May 7, 2009 · Viewed 590.4k times · Source

Isn't there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar?

Answer

Ben Noland picture Ben Noland · May 7, 2009
GregorianCalendar c = new GregorianCalendar();
c.setTime(yourDate);
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);